Autor Beitrag
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Di 31.07.07 14:59 
Ich möchte den UNIX-Timestamp der ersten Sekunde eines bestimmten Tages herausfinden.
Hintergrund:
Ich entwickle einen Eventlogger. Beim Abspeichern eines Events wird die aktuelle Zeit als Timestamp in der DB hinterlegt. Nun möchte ich anhand eines Datums alle Events auflisten lassen, die genau an diesem Tag passiert sind. Also muss der Timestamp eines Events, dass in Frage kommt, größer als die erste Sekunde des Tages und kleiner als die nächste Sekunde das folgenden Tages sein. Ist das richtig?
Zum Umwandeln eines Timestamps in ein Datum verwende ich:
ausblenden C#-Quelltext
1:
2:
3:
4:
public function ListByDate($date) {
   $stamp = strtotime($date);
   ...
}

Und wie erhöhe ich $date um 1, also wie gehe ich zum nächsten Tag?
Das Datumsformat wird dd.mm.yyyy sein.

_________________
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot
ene
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 779
Erhaltene Danke: 1

Vista, XP, W2K
Delphi, .Net, Deutsch und Englisch
BeitragVerfasst: Di 31.07.07 15:02 
Hi,

reicht es nicht einfach den entsprechenden Tag abzufragen? Denn 24:00 gibt es nicht und bei 23:59:59 ist der Tag zu ende.

_________________
Wir, die guten Willens sind, geführt von Ahnungslosen, Versuchen für die Undankbaren das Unmögliche zu vollbringen.
Wir haben soviel mit so wenig so lange versucht, daß wir jetzt qualifiziert sind, fast alles mit Nichts zu bewerkstelligen.
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: Di 31.07.07 15:22 
Datum in Timestamp: mktime();
Timestap zu Datum: date();

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Di 31.07.07 20:08 
Typische Anwendung für mktime:
1. Abzufragendes Datum getrennt in Tag, Monat und Jahr angeben und an mktime übergeben
2. Zum Datum 86400 addieren
3. Filtern nach Start <= Datum < Ende

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Arne K.
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
EE-Autor
Beiträge: 112


C# (VS 2008 Professional)
BeitragVerfasst: Di 31.07.07 22:05 
Ganz ehrlich? Ich würde mir das Theater mit den Timestamps sparen:
ausblenden Quelltext
1:
2:
3:
if(date('dmY') === date('dmY', $timestamp))   {
   // Whatsoever
}
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mi 01.08.07 09:56 
Nur schade, dass die meisten DBs date nicht direkt unterstützen für Timestamps ;-) Von daher ist es normales Vorgehen, das über die Timestamps zu machen. die von der DB unterstützen Datum-\Zeit-Funktionen sind zwar gut und schön, wenn man aber nur filtern muss, sind numerische Abfragen nach den Unix-Timestamps schneller.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Arne K.
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
EE-Autor
Beiträge: 112


C# (VS 2008 Professional)
BeitragVerfasst: Mi 01.08.07 14:01 
Sicher, aber man erspart sich das rumrechnen und der Code wird (meiner Meinung nach) übersichtlicher.
Und ich denke, PHP hat ganz andere Geschwindigkeitslecks, als dass eine Umformung zweier Timestamps ins Gewicht fallen würden ;)