Forum Moderators: coopster

Message Too Old, No Replies

Converting date time to seconds from Unix Epoch

         

otem

12:16 am on Mar 8, 2007 (gmt 0)

10+ Year Member



I was hoping someone could help me convert a date to seconds. I thought this was going to be easy, but the script so far has gotten the best of me.

I have a date in the format of "YYYY-MM-DD HH:MM:SS", lets say its "2007-03-07 07:25:56".

I am trying to output this stamp into "March 7th".

So I'm using the following code:

date("F jS","2007-03-07 07:25:56");

This code isn't working, which made me realize I needed to convert my date into seconds from 1970. Something like the following pseudo code:

date("F jS",secondsfrom1970("2007-03-07 07:25:56"));

What is the best way to convert my date time to seconds?

Thank you

jatar_k

12:34 am on Mar 8, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



split it up and feed it to mktime [php.net] to get your timestamp for date

ksks

12:48 am on Mar 8, 2007 (gmt 0)

10+ Year Member



$t = '2007-03-07 07:25:56';
$t2 = date('F jS', strtotime($t));
echo $t2;

otem

6:12 am on Mar 12, 2007 (gmt 0)

10+ Year Member



Thank you very much. That function worked great.