Get Date from Datetime String [duplicate] - php

This question already has answers here:
convert strtotime to date time format in php
(5 answers)
Closed 9 years ago.
This is my String Tue, 20 Aug 2013 10:45:05
and i want to this string in Date Format Like this :
2013-08-20.
Guys Please help.
Thanks

Something like this:
echo date('Y-m-d', strtotime('Tue, 20 Aug 2013 10:45:05'));

Try this,
$d=date('Y-m-d',strtotime('Tue, 20 Aug 2013 10:45:05'));
echo $d;

Related

Hot to convert string into date in php [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 4 years ago.
I have a string
date = 25 aug 18
is there any way to convert this into date time format,
date = 25 August 2018
Use:
echo date('d F Y', strtotime("25 aug 2018")). "\n";
output: https://3v4l.org/2T9NF
refer:
http://php.net/manual/en/function.strtotime.php
http://php.net/manual/en/function.date.php

php string replace $date [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 6 years ago.
After searching still problems with string replace
My $date looks like
Sat, 11 Feb 2017 11:33:38 +0100
I need only the date part (YYYY-MM-DD):
2017-02-11
Please can somebody help.
Thank you!
Best regards,
Roman
Use
date("Y-m-d", strtotime($date));
$date is var name that contain like Sat, 11 Feb 2017 11:33:38 +0100
use
date("Y-M-D", strtotime($date));

Php convert a date to string character [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 6 years ago.
I have searched but I could not find out how to convert a date from a character string. For example string date is 18-08-2016 I want to convert 18 August 2016 How can I do?
$input = '18-08-2016';
echo strftime('%d %B %Y',strtotime($input));// 18 August 2016
Use this resource to format the output to your liking.

Convert sql date to DD/MM/YYYY with PHP [duplicate]

This question already has answers here:
Convert a date format in PHP [duplicate]
(18 answers)
Closed 7 years ago.
I've got an SQL server 2000 running with some data.
When I select one of my fields I get something like this:
Sep 21 2015 12:00:00:000AM
Sep 14 2015 12:00:00:000AM
..etc
I would like to convert this thing to "DD/MM/YYYY".
When I'm doing a query with Access I get this format, but not with PHP.
`your query and see time and take it into a variable then fetch that index that comes with time make three array like
`$ar=array();
$ar1=array();
$ar2=array();` after it apply `$ar1[0]=$ar2[0];
$ar1[2]=$ar[1];
$ar1[3]=$ar[0]." ".$ar2[1];
then implode like
$dt=implode("-",$ar1);
$data[$k]['time_from']=$dt;
and print $dt you find your structure.
$timestamp = '31/05/2001 12:22:56';
$timestamp = DateTime::createFromFormat('d/m/Y H:i:s', $timestamp);
echo $timestamp->format('Y-m-d H:i:s');

How do I convert a formatted date into a unix timestamp? [duplicate]

This question already has answers here:
How to convert date to timestamp in PHP?
(22 answers)
Closed 9 years ago.
How can I convert a date in the following format to a unix timestamp?
Thu, 26 Dec 2013 17:53:05 +0100
Thanks, Regards !
Use strtotime:
For example,
echo(strtotime("Thu, 26 Dec 2013 17:53:05 +0100"));
will output
1388076785
strtotime will give you a unix timestamp from a date string, provided it's in a valid format.
Verbose version (oop / robust):
$dateString = 'Thu, 26 Dec 2013 17:53:05 +0100';
$date = DateTime::createFromFormat(
DateTime::RSS,
$dateString,
new DateTimeZone('UTC')
);
echo $date->getTimestamp().PHP_EOL // 1388076785
.$date->format('r').PHP_EOL; // Thu, 26 Dec 2013 17:53:05 +0100
: demo

Categories