Hot to convert string into date in php [duplicate] - php

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

Related

In php I have timestamp stored in session or cookie. How To Convert That Timestamp To Date & Time Format? [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 5 years ago.
Need Solution For Providing Date And Time.
Have a look to DateTime::createFromFormat:
$dt = DateTime::createFromFormat('d M Y h:i:s O', '01 Feb 2018 01:01:12 +0530');
echo $dt->format("Y-m-d H:i:s");
try this
$date = "Thu, 01 Feb 2018 01:01:12 +0530";
echo date("Y-m-d H:i:s",strtotime($date));

PHP display date as month name and date [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 5 years ago.
I am getting current date using the function date("Y-m-d").
I want to display date 2017-09-12 as sep 12
You can present it as ("M j"). Here is a test version.
this will do: date_format($date,"M/d");
Here is your date..
$myDate = "2017-09-12";
Then you have to convert your date with Date PHP function
$date = date("M d",mktime("0 0 0 ".$myDate));
echo $date will print Sep 12
d is Day of the month, 2 digits with leading zeros
M is a short textual representation of a month, three letters

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.

Specify my date PHP [duplicate]

This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 6 years ago.
I have attribut date_input in my database
etat_input : 2016-06-06
I would convert my date on format:
since : 06 june 2016
I try with :
<?php echo $var['etat_input'];?>
but no result.
First convert date_input to timestamp:
$timestamp = strtotime($var['etat_input']);
Now feed that $timestamp to date with proper format:
date('d M Y', $timestamp);
PHP Sandbox example

Get Date from Datetime String [duplicate]

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;

Categories