PHP Date conversion to unix-timestamp [duplicate] - php

This question already has answers here:
How to convert date to timestamp in PHP?
(22 answers)
Closed 8 years ago.
How do yo convert this 2014-11-03 17:01:37 into Unix Timestamp?
Is there a method that I can use.

You can create a DateTime object:
$time = new DateTime("2014-11-03 17:01:37");
$time->getTimestamp();

use - strtotime()
$date = "2014-11-03 17:01:37";
echo strtotime($date);

strtotime('2014-11-03 17:01:37')

PHP has a function strtotime for that purpose.
echo strtotime("2014-11-03 17:01:37");

Related

How to convert seconds from date format and hour format [duplicate]

This question already has answers here:
PHP convert datetime to seconds
(4 answers)
Closed 5 years ago.
Now my output here:
$date = 25.10.17 02:35:57;
$seconds = ??????;
Because Now my php date output has standard date format.so how to i'm convert
Seconds Format.please Answer me...
You can use strtotime() function of php to covert given time in seconds
<?php
$date = '25.10.17 02:35:57';
echo strtotime($date);
?>
You can read more about function http://php.net/manual/en/function.strtotime.php

Convert date to W3C format [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 5 years ago.
I have date format (YYYY-MM-DDThh:mm:ss.u):
2017-05-05T18:20:26.000Z
I need to convert it, so it will be without ms (.u) and to add GMT zone at the end of it (YYYY-MM-DDThh:mm:ss+TZD):
2017-05-05T18:20:26+00:00
How to do that? Should I use format() or date_format()?
Thank You!
You could use DateTime::createFromFormat().
$datestring = "2017-05-05T18:20:26.000Z";
$date = DateTime::createFromFormat("YYYY-MM-DDThh:mm:ss.u", $datestring);
Then use format() on $date as you need it.
DateTime::createFromFormat()
DateTime::format()

How to change date format dmYhis to Y-m-d in PHP [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Convert this string to timestamp PHP [duplicate]
(2 answers)
Convert a date format in PHP [duplicate]
(18 answers)
Closed 5 years ago.
How to change date format dmYhis to Y-m-d in PHP. I have using the date() function but I cannot seem to make it work
$d = '24032017191551';
echo date('Y-m-d', strtotime($d));
Output: 1970-01-01
i want to get the ans is 2017-03-24
Below is the code to change date format
$retrieved ='24032017191551';
$date = DateTime::createFromFormat('dmYHis', $retrieved);
echo $date->format('Y-m-d');

PHP Convert Date/Time Format to another [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 7 years ago.
I have a Date/time value as such;
2014-01-07T16:19:08Z
I wish to convert it to the format below using PHP
2015-03-21 02:12:01
I know I could use string replace twice over to remove the T and Z characters but doesn't seem right..
use strtotime() with date()
echo date('Y-m-d H:i:s',strtotime('2014-01-07T16:19:08Z'));
The date_format() function returns a date formatted according to the specified format.
$date=date_create("2014-01-07T16:19:08Z");
echo date_format($date,"Y-m-d H:i:s");
One more way is there
echo date('Y-m-d H:i:s',strtotime('2014-01-07T16:19:08Z'));
Update
The date_create() function returns a new DateTime object.
Reference
<?php
echo date('Y-m-d H:i:s',strtotime('2014-01-07T16:19:08Z'));
?>

Get a timestamp from a day,year, and month [duplicate]

This question already has answers here:
How to convert date to timestamp in PHP?
(22 answers)
Closed 9 years ago.
I have the following string: 2013-03-22
I need to convert that to a UNIX Timestamp.
How do I do this using PHP?
Use the strtotime function of PHP.
Like
$unixstamp = strtotime("2013-03-22");
With DateTime class
$dateTime = DateTime::createFromFormat('Y-m-d', '2013-03-22');
$dateTime->setTime(0, 0, 0);
echo $dateTime->getTimestamp();
Simple:
echo $time = strtotime("2013-03-22");
Using
strtotime("2013-03-22")
It will convert the date sting into timestamp value.

Categories