Forum Moderators: coopster

Message Too Old, No Replies

Couldn't get an accurate representation from this date format...

         

irock

12:19 am on Sep 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a variable that has a value of 20030922171658. I would like to use PHP to print it as Sept. 2003.

I used this code with no success... got Jan. 2038 instead.
print date("M. Y",$row[release]);

Could anyone help?

daisho

3:28 am on Sep 23, 2003 (gmt 0)

10+ Year Member



20030922171658

What is the 171658?

daisho.

irock

3:32 am on Sep 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Military time I guess:
17:16:58

mogwai

8:21 am on Sep 23, 2003 (gmt 0)

10+ Year Member



The date function requires a unix timestamp to be passed in. You will need to firstly convert this string to a timestamp using strtotime().

print date("M. Y",strtotime($row[release]));

However, although the strtotime function accepts many different input formats I don't believe 20030922171658 is one of them, don't quote me on that, give it a try. I would advise you to first convert this to a valid input format for strtotime and then use the function above to output the format you require.

If your date string is always in this format you could write a simple function to break it up into an acceptable format such as, 2003-09-22 17:16:58.

Hope this helps.

daisho

12:30 am on Sep 24, 2003 (gmt 0)

10+ Year Member



lol. Good eye irock. Not sure what planet I was on when I didn't pick that one up :)

Take a look at PHP mktime() function [php.net]. To get the parameters look at substr() function [php.net] to cut out the different parts. mktime() will then give you a unix timestamp. Do with that what you will...

daisho.