Hi I want change date string -> Sat Oct 04 00:00:00 GMT+05:30 2008 -> into 'Y-m-d H:i:s' format my code is as below :
$lsd = strtotime($vehicle->newDate);
$newDate = date('Y-m-d H:i:s',$lsd);
I am getting date like 1970-01-01 05:30:00 Why is so ?
I have gone through reference : http://php.net/manual/en/function.date.php
I have got date fromat representation labels for all except GMT+05:30
Sat Oct 04 00:00:00 GMT+05:30 2008
D M d H:i:s o
Instead of down-votes if that one label I get then I will be thankful then I will use http://php.net/manual/en/datetime.format.php,
Use this one.
$lsd = strtotime("Sat Oct 04 00:00:00 GMT+05:30 2008");
$newDate = date('Y-m-d H:i:s',$lsd);
echo $newDate;
Try this
$lsd = strtotime($vehicle->newDate);
$newDate = date("D M j G:i:s T Y");
Related
How to get this type of date in PHP like this
Date {Fri Jun 24 2016 10:30:06 GMT+0530 (IST)}
jQuery standerd format.
Try:
Also refer http://php.net/manual/en/function.date.php for different date formats
echo date("D M d Y h:i:s eO T");
Output:
Fri Jun 24 2016 10:52:42 Asia/Calcutta+0530 IST
As you were looking for ยป RFC 2822 formatted date you can simply use
echo date("r"); // Fri, 24 Jun 2016 10:59:36 +0530
Or if you want to be somewhat like as question you can use
echo date("D M d Y H:i:s eO T"); // Fri Jun 24 2016 10:59:37 Asia/Kolkata+0530 IST
Docs
In PHP you can get this format as
<?php
$tzone = new DateTimeZone('Asia/Calcutta');
$dtime = new DateTime("now", $tzone);
echo $dtime->format("D M d Y H:i:s \G\M\TO (T)");
?>
In that case you will get the output:
Fri Jun 24 2016 11:25:40 GMT+0530 (IST)
That is your output as you wanted.
finally got it .... thanks for help..
$tzone = new DateTimeZone('Asia/Calcutta');
$dtime = new DateTime("now", $tzone);
$daet = $dtime->format("D M d Y H:i:s \G\M\TO (T)");
$timestart = explode (' ', microtime());
$timeInSecond = substr($timestart[0],1,4)."Z";
echo preg_replace('/\+.*/',$timeInSecond,date('c',"1466774626"));
//2016-06-24T15:23:46.541Z
I have a php script that returns the date of the server:
<?php
echo date('D, d M y H:i:s a');
?>
but when I print this value on the client site I get:
Tue, 29 Sep 15 16:19:28 pm
But instead I need the date in this format:
Tue Sep 29 2015 16:18:00 GMT+0200 (Central Europe Daylight Time)
How should I modify my php script then to have it like this?
Thanks!
echo (new DateTime())->format('r');
$datestring = "26-08-2015 03:35:28"; //date as string
$date = new DateTime($datestring); //String to datetime conversion
$date = $date->format('D d M y H:i:s O e'); //format the date
echo $date;
This is the manual link. Timezone you have to set.
Output will look like Wed 26 Aug 15 03:35:28 +0200 Europe/Paris
Go to the very bottom of this page http://php.net/manual/en/function.date-default-timezone-set.php
I have a string in this format:
Thu, 26 Feb 2015 11:39:59
And I wonder if its possible to transform it to a valid timestamp format in order to insert it in my PostgreSQL database.
So ideally in the end I would have something like:
2015-03-26 11:39:59
Is there a function in PHP to do something like this?
Use DateTime() to format date string.
$date = 'Thu, 26 Feb 2015 11:39:59';
$date = new DateTime($date);
echo $date->format('Y-m-d H:i:s');
You can also use it as DateTime::createFromFormat
$date = 'Thu, 26 Feb 2015 11:39:59';
$date = DateTime::createFromFormat('D, d M Y H:i:s', $date);
echo $date->format('Y-m-d H:i:s'); //2015-03-26 11:39:59
I have a timestamp as 2011-08-27 18:29:31. I want to convert it to 27 Aug 2011 06.29.31 PM. Also, I want to convert this format reverse back to the previous timestamp format.
How van I do this using PHP?
$converted = date('d M Y h.i.s A', strtotime('2011-08-27 18:29:31'));
$reversed = date('Y-m-d H.i.s', strtotime($converted));
Don't use date()! It`s too old function. In PHP v. 5.2 and more you should use date_format or DateTime::format object.
you can use the date_format() function
//Convert to format: 27 Aug 2011 06.29.31 PM
$converted_date = date_format('d M Y h.i.s A',strtotime($orig_date));
//Convert to format 2011-08-27 18:29:31
$converted_date = date_format('Y-m-d H:i:s',strtotime($orig_date));
Have you looked at the date functions in PHP, especially strftime (for formatting a timestamp) and strtotime
To convert from 2011-08-27 18:29:31 to 27 Aug 2011 06.29.31 PM:
echo date('d M Y, H.i.s A', strtotime('2011-08-27 18:29:31'));
To do the reverse:
echo date('Y-m-d H:i:s',strtotime('27 Aug 2011 06.29.31 PM'));
If that doesn't work, you may have to try:
$date = date_create_from_format('d M Y, H.i.s A', '27 Aug 2011 06.29.31 PM');
echo date_format("Y-m-d H:i:s",$date);
I've a date formatted like "Tue Jan 05 11:08:27 +0000 2010" and I want to convert it's format to "yyyy-mm-dd 00:00" in PHP.
How can I do that?
convert it to a PHP date object with strtotime() then output it with date()
EDIT
Some more detail; try:
$time = strtotime('Tue Jan 05 11:08:27 +0000 2010');
echo date("Y-m-d h:i", $time);
Y = 4 digit year
m = 2 digit month (with leading 0)
d = 2 digit month (with leading 0)
h = 12 hour time (leading 0)
i = minutes (with leading 0)
http://php.net/manual/en/function.date.php
for all the formatting options
$time_string = 'Tue Jan 05 11:08:27 +0000 2010';
$formated_time = date('Y-m-d h:i', strtotime($time_string));
echo $formated_time;
strtotime + date
Agree with Erik, if you want to do it in one line.
Solution
$date = date('Y-m-d H:i:s', strtotime('Tue Jan 05 11:08:27 +0000 2010'));