I would like to get the actual date + time, and convert it (the time) to a 24 hour format (e.g: 15/04/2017 13:32:02)
My current code is :
date_default_timezone_set("Asia/Magadan");
$date = date("d/m/Y h:i:s");
echo $date;
That display :
15/04/2017 01:32:02
Thanks.
Put the h capital for 24 hour format date("d/m/Y H:i:s");
Finally, to change to a 24 hour format we only have to change the H of the hour to a MAJ/CAPS.
$date = date("d/m/Y H:i:s");
http://php.net/manual/en/function.date.php
convert (h:i:s) to (H:i:s) . that's worked for me
Related
I have this function
$timetable->start_time = $row{'deadline_time'} ? date('H:i', strtotime($row{'deadline_time'})) : ''; // start_time : Must be 24 hour format. For example: 18:00
$timetable->end_time = $row{'deadline_time'} ? date('H:i', strtotime($row{'deadline_time'})) : ''; // end_time : Must be 24 hour format. For example: 20:30
And i need to add -30 minutes to that time. How can I add it?
#UPDATE
I just update the code..
So the code is the same for start and end I just need to add -30 mins to the start. :)
You can add / substract specific lengths of time as follows:
$date = date("Y-m-d H:i:s");
echo date("Y-m-d H:i:s", strtotime($date . '-30 minutes'));
Try this:
echo date('H:i:s', strtotime("-30 minutes"));
Lookup strtotime
I tried to save time in format YYYY-mm-dd 23:59:59 to mysql database column with datetime. I don't understand why minutes and seconds are ignored always 00 ? Thank you very much for help.
PHP:
$time = strftime('%Y-%m-%d %H:%i:%s', time());
Output:
2014-07-16 11:00:00
You can simple use:
$time = date("Y-m-d H:i:s");
or even better use mysql NOW() function
you have to specify timezone as follows.
date_default_timezone_set('Australia/Melbourne');
$date = date('m/d/Y h:i:s a', time());
echo $date;
The time would go by your server time. An easy workaround for this is to manually set the timezone by using date_default_timezone_set before the date() or time() functions.
you can use mysql function
now()
You are looking for
$time = strftime('%Y-%m-%d %H:%M:%S', time());
from the documentation
%S Two digit representation of the second
%M Two digit representation of the minute 00 through 59
Also, what PHP version are you using? %i:%s should not be 00:00
I am having trouble adding a time and time interval to a date.
I use a javascript datepicker that gives date in the form: 05/06/2013
I can convert this into a date time format with
$eventdate = date("Y-m-d H:i:s",strtotime($eventdate));
This gives: 2013-05-06 00:00:00
I get the time from a separate variable in minutes. Eight o'clock would be 480.
However, I cannot seem to find syntax to add 480 minutes to the date.
Have tried, for example,
echo date("Y/m/d h:i:s", strtotime("+480 minutes", $eventdate));
but this gives me the default 1969 date.
Thanks for any help or suggestions!
Use the DateTime class, it's easier to work with:
$eventdate = \DateTime::createFromFormat('Y/m/d h:i:s', $eventdate);
$eventdate->modify('+480 minutes');
echo $eventdate->format('Y/m/d h:i:s');
In my Mysql table I have a timestamp field.
In my php page I show the record ($row[data]) in this way
echo date("d-m-Y H:i:s", strtotime($row['data']));
Now in my php I'd like to add 1 hour on my date.
How can I do this?
Thanks
echo date("d-m-Y H:i:s", strtotime($row['data'])+3600);
note that you can't compare resulting dates in "d-m-Y" format.
either compare strtotime results or initial dates. or format your results into proper format first.
You could do this straight away in MySQL:
SELECT `date` + INTERVAL 1 HOUR AS `date`
FROM ...
echo date("d-m-Y H:i:s", strtotime($row['data'].' +1 hour'));
Try with:
strtotime($row['data'] . ' +1 hour')
echo date("d-m-Y H:i:s", strtotime($row['data']) + 3600);
Just add the time manually (3600 seconds = 1 hour).
Add 3600 seconds and you will be fine.
echo date("d-m-Y H:i:s", strtotime($row['data'])+3600);
I am using following function and I want time in 24hr clock format but this gives me time in 12hrs:
<?php
date_default_timezone_set('Asia/Kolkata');
$timestamp = date("d/m/Y h:i:s", time());
print $timestamp ;
?>
What am I doing wrong?
From the docs for date(): The H format character gives the hour in 24h format. Also, you can use G if you do not want the leading 0 for hours before noon.
Examples (if current time was seven-something-AM)
date('H:i:s') -> "07:22:13"
date('G:i:s') -> "7:22:13"
For your specific case:
$timestamp = date("d/m/Y H:i:s", time());
According to the manual the difference is in the capitalization of hour portion:
"h" returns a 12-hour format of an hour with leading zeros, 01 through 12.
"H" returns a 24-hour format of an hour with leading zeros, 01 through 23.
According to the manual, G or H give you the time in 24-hour format. You should read the manual.
date('H', time());
The H format character gives the hour in 24h format. Also, you can use g if you do not want the leading 0 for hours before noon.
// 24-hour time to 12-hour time
$time_in_12_hour_format = date("g:i a", strtotime("13:30"));
// 12-hour time to 24-hour time
$time_in_24_hour_format = date("H:i", strtotime("1:30 PM"));