Jump to content

[SOLVED] UK not US date?


the_oliver

Recommended Posts

Ok, so i have go that

 

$today = date("F j, Y");
echo $today;

 

will give me the format October 15, 2006.  But i want to do this of a result stored in a database.  So i tried:

 

$time = 2007-03-07;
$today = date("F j, Y", $time);
echo $today;

 

(as 2007-03-07 is the format stored in the database)

 

But that gives me January 1, 1970 not March 7, 2007.  Where have i gone wrong??

 

Thanks.

 

Link to comment
https://forums.phpfreaks.com/topic/43235-solved-uk-not-us-date/#findComment-211237
Share on other sites

The second parameter to the date() function is a UNIX time stamp, so you have to convert the date string to that. The easiest way is to use the strtotime() function.

<?php
$time = 2007-03-07;
$today = date("F j, Y", strtotime($time));
echo $today;
?>

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/43235-solved-uk-not-us-date/#findComment-211252
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.