Closed Thread Icon

Preserved Topic: Date and Time conversion in PHP (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=21191" title="Pages that link to Preserved Topic: Date and Time conversion in PHP (Page 1 of 1)" rel="nofollow" >Preserved Topic: Date and Time conversion in PHP <span class="small">(Page 1 of 1)</span>\

 
Skaarjj
Maniac (V) Mad Scientist

From: :morF
Insane since: May 2000

posted posted 04-06-2003 08:48

As with almost all server-side questions I ask...this has been cross-posted over at the Gurus Network..

I've got a quandry on my hands. I need to take a time in HH:MM and convert it to a unix timestamp. I also need to take a time-stamp of the current time in a unix timestamp. From there I need to use the first time stamp and compare it to the second to determine if the first time is past or future. If it's past run this function, if it's future run this function.

Oh, and I also need to take a date and add 14 days to it and then write it back into the table I pulled it out of...any ideas?

Perfect Thunder
Paranoid (IV) Inmate

From: Milwaukee
Insane since: Oct 2001

posted posted 04-06-2003 12:57

First off, if you've got a date/time in any reasonable format, you can use the strtotime function to turn it into a UNIX timestamp.

Second, knowing that a UNIX timestamp is the number of seconds since the beginning of 1970, you can easily add 14 days to it. Just use normal addition to increase it by (14 days * 24 hours * 60 minutes * 60 seconds).

Third, since a UNIX timestamp is a straight integer, it's easy to compare two of them to get past and future.

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 04-06-2003 18:38

current server-timestamp would be time().
date($format) converts timestamps back to something human-readable.
you might need to do something like strtotime(date('Y-m-d '). $myHHIItime) to get what you want (note that minutes are I in the date format string, not m ;-). Be sure to read that up.)

Skaarjj
Maniac (V) Mad Scientist

From: :morF
Insane since: May 2000

posted posted 04-07-2003 08:30

Thanks guys...I've got all my functions written now, now onto the relativley easy main code...I've just got to do some user authentication things and a whole bunch of access pages and then I'm done...after this (if they agree to buy this iteration of it) I just have to pretty it up to their specifications.

« BackwardsOnwards »

Show Forum Drop Down Menu