convert date

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
valen53
Forum Contributor
Posts: 137
Joined: Tue Aug 27, 2002 9:29 am

convert date

Post by valen53 »

hi, all
i face a problem, when i mkdate (), the date was increase a day.
such as i get today as $date_from.... 26/03/2003.
when i echo it...
echo date("m/d/Y", mktime($date_from)) ;
the date was 03/27/2003...

any method can be reduce the day?

Thank you for help.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

It's showing you today's date because you are using the mktime() function incorrectly:

Code: Select all

mktime ( int hour, int minute, int second, int month, int day, int year ї, int is_dst])
Instead of doing this:

Code: Select all

$date_from = '26/03/2003'; 
echo date("m/d/Y", mktime($date_from));
you need to do something like:

Code: Select all

$date_from = explode('/', '26/03/2003');
$timestamp = mktime(0, 0, 0, $date_from[1], $date_from[0], $date_from[2]);
echo date('m/d/Y', $timestamp);
Mac
Post Reply