Autor Beitrag
Wolle92
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Mi 23.01.08 15:32 
Hallo,
ich möchte zwei Zeiten in PHP vergleichen, die eine davon wird aus einer MySQL-Datenbank gelesen...
In der Form YYYY-MM-TT HH:MM:SS...
Die andere ist die aktuelle Zeit, als Ergebnis der Funktion Time()...
Um dann damit rechnen zu können, will ich jetzt alles auf das Time()-Ergebnis-Fomat bringen...
Wie mache ich das?

Wolle

_________________
1405006117752879898543142606244511569936384000000000.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mi 23.01.08 15:52 
ausblenden Quelltext
1:
2:
3:
$sql = mysql_query("SELECT UNIX_TIMESTAMP(dateCol) AS TimeStamp FROM dateTable");
$result = mysql_fetch_assoc($sql);
$timestamp = $result['TimeStamp'];

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Mi 23.01.08 15:55 
Aber die Time-Funktion liefert ja keinen Unix-Timestamp zurück...
sonder sowas:
1201096462
nen Unix-Timestamp ist doch IMHO 20080123145416, oder?

_________________
1405006117752879898543142606244511569936384000000000.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Mi 23.01.08 22:07 
Nein. Ein Unix-Timestamp - time() gibt so einen aus - gibt die Sekunden seit dem 01.01.1970 an. Und das ist das was du möchtest ;-)

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Christian V.
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 311

Win Xp Prof
Turbo Delphi 2005
BeitragVerfasst: Do 24.01.08 00:16 
user profile iconGTA-Place hat folgendes geschrieben:
Nein. Ein Unix-Timestamp - time() gibt so einen aus - gibt die Sekunden seit dem 01.01.1970 an. Und das ist das was du möchtest ;-)

Was er möchte....
Wohl eher, wonach er gefragt hat ;)

Nun, das was du willst kannst du folgendermassen erreichen:
Du löschst einfach mittels RegEx alles raus, was keine zahlen sind. ;) Also einfach mit \D matchen, und mit '' ersetzen.

_________________
Hardware runs the world, software controls the hardware, code generates software - Have You already coded today?
DarkHunter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 477

Win XP
D3 Prof, D2005 PE
BeitragVerfasst: Do 24.01.08 00:28 
Wenn das Format immer YYYY-MM-TT HH:MM:SS ist, dann kannst du über einen Regex und die Funktion mktime() einen Timestamp draus machen.
Regex: (\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)

in php würde das ganze so aussehen:
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
$data = <daten aus der mysql-datenbank>;
$regex = "/(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/i";
$date = array();
if (preg_match($regex,$data,$date)){
  $year = $date[1];
  $month = $date[2];
  $day = $date[3];
  $hour = $date[4];
  $min = $date[5];
  $sec = $date[6];
  $timestamp = mktime($hour,$min,$sec,$month,$day,$year);
}


Anmerkung: Code ist nicht getestet, sondern soll nur als Hinweis dienen.

_________________
I believe that every human has a finite number of heart-beats. I don't intend to waste any of mine running around doing exercises.
- Neil Armstrong
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Do 24.01.08 07:40 
Das ist doch Blödsinn. Wozu gibt des denn die Funktion UNIX_TIMESTAMP von MySQL?

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: Do 24.01.08 16:09 
Leute, GTA hat recht...
Muss man einfach mal in PHPMyAdmin eingeben...
ausblenden Quelltext
1:
SELECT UNIX_TIMESTAMP(time) FROM table					

Kommt genau so eine zehnstellige Zahl raus wie bei der Time()-Funktion...

Leider weiß ich jetzt nicht mehr, wofür ich das brauchte...

_________________
1405006117752879898543142606244511569936384000000000.
Christian V.
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 311

Win Xp Prof
Turbo Delphi 2005
BeitragVerfasst: Sa 26.01.08 19:09 
user profile iconWolle92 hat folgendes geschrieben:
Aber die Time-Funktion liefert ja keinen Unix-Timestamp zurück...
sonder sowas:
1201096462
nen Unix-Timestamp ist doch IMHO 20080123145416, oder?

Was möchstest du den nun? Den Unix Timestamp, oder das von dir beschriebene Format?

GTA's Lösung ist für den Unix Timestamp gedacht. Dein Problem, etwas wie 20080126180120 ausgeben, löst es nicht!

Wie gesagt, einfach die preg_replace Funktion benutzen.
ausblenden C#-Quelltext
1:
2:
3:
4:
<?PHP
  $time = '2008-01-26 18:02:21';
  $result = preg_replace('~\D~''', $time);
?>

_________________
Hardware runs the world, software controls the hardware, code generates software - Have You already coded today?
Wolle92 Threadstarter
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 1296

Windows Vista Home Premium
Delphi 7 PE, Delphi 7 Portable, bald C++ & DirectX
BeitragVerfasst: So 27.01.08 10:23 
hab doch schon gesagt, das GTAs Antwort richtig ist...

_________________
1405006117752879898543142606244511569936384000000000.
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: So 27.01.08 10:52 
user profile iconChristian V. hat folgendes geschrieben:
Was möchstest du den nun? Den Unix Timestamp, oder das von dir beschriebene Format?

user profile iconWolle92 hat folgendes geschrieben:
Um dann damit rechnen zu können, will ich jetzt alles auf das Time()-Ergebnis-Fomat bringen...


;-)

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)