Arundev PV
Arundev PV

Reputation: 41

PHP date/time function not work properly?

Why the following two will get same Result??

echo date('d/m/Y',1338156000); will produce output 28/05/2012

And echo date('d/m/Y',1338143400); also produce the same out put 28/05/2012 ??

Upvotes: 0

Views: 773

Answers (4)

developerCK
developerCK

Reputation: 4506

Yes Both will give the same date because time stamp is in seconds.if you print first like

echo date("d/m/y h:i:s", 1338156000);

it will give you result like

28/05/2012 03:30:00

and

echo date('d/m/Y h:i:s',1338143400); 

result is

28/05/2012 12:00:00

for further reference check php date and time manual

Upvotes: 2

Vijaya Pandey
Vijaya Pandey

Reputation: 4282

Quite Simple

<?php 
    echo date('d/m/Y',1338156000); 
    echo "<br />";
    echo date('d/m/Y',1338143400); 
    echo "<br />";

    echo date('d/m/Y H:i:s',1338156000); 
    echo "<br />";
    echo date('d/m/Y H:i:s',1338143400); 
    echo "<br />";


?>

Here, when 27/05/2012 22:00:00 the day is: 27

and when 27/05/2012 18:30:00 the day is: 27

Upvotes: 2

Hanky Panky
Hanky Panky

Reputation: 46900

As stated by others, its the same date that's why the confusion. But if you simply add time to your own code along with the date your confusion will itself be gone without asking.

<?php
echo date('d/m/Y H:i:s',1338156000);
echo "<br>";
echo date('d/m/Y H:i:s',1338143400);
?>

Upvotes: 1

sectus
sectus

Reputation: 15464

Difference of this values is 3.5 hours. So, it is times of one day.

Upvotes: 2

Related Questions