0

When I am using the php date() function, the result is not correct. It is not just the timezone who is not correct because the time given has always the same Year, Month, Day, Hour, Minute. The only thing which evolves is the number of seconds.

<?php
    $time = date('Y-m-d H:m:s');
    var_dump($time);
?>

For example if I run the following script one time I will get :

string(19) "2014-04-01 02:04:41"

And the second time (32 second after the first one), I get :

string(19) "2014-04-01 02:04:12"

I really do not understand what is happening. My PHP version is the 5.5.10 but I also used the 5.4.17. Both running on Mac OS X 10.9.1

6 Answers 6

4

You are displaying the month where you intended to display the minutes. i is the marker for minutes with leading zero.

Your code: $time = date('Y-m-d H:m:s');

Correct way: $time = date('Y-m-d H:i:s');

Sign up to request clarification or add additional context in comments.

1 Comment

My bad. Thanks for the fast answer ! :)
2

m is for months, not minutes. i is for minutes. Change:

$time = date('Y-m-d H:m:s');

to

$time = date('Y-m-d H:i:s');

Comments

2

Your problem is in your format string. The format code for minutes is i, not m, which is the code for months.

Use this:

$time = date('Y-m-d H:i:s')

Comments

0

Change the m to i

m is for months i is for minutes

Change

$time = date('Y-m-d H:m:s');

to

$time = date('Y-m-d H:i:s');

For other formats and reference regarding date function visit

http://php.net/manual/en/function.date.php

Comments

0

"m" is for month and "i" for minutes

here s what your code should look like

<?php
$time = date('Y-m-d H:i:s');
var_dump($time);

?> check out manual for more examples source : http://php.net/manual/en/function.date.php

Comments

0

To have correct Current Timing with seconds no need to set the date_default_timezone_set("Asia/Calcutta"); Method . For more details on this visit php timezone link

 <?php
date_default_timezone_set("Asia/Calcutta");
echo "The Current Date & time is " . date("d/m/Y h:i:sa");
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.