This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 6 years ago.
Hi all i want to convert mdy format of date to ymd format
$todate = '03-31-2016;
I am using this code to convert it
$todate = date("Y-m-d", strtotime($todate));
This code gives me output
1969-12-31
so whats the right way to do it?
Thanks
Try this code
$date = '03-31-2016;
$todate = date("Y-m-d", strtotime($date));
Related
This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 5 years ago.
I have a date that gets sent from a database which comes in a string format of '2018-01-01'. What I want to do is convert it into a string of month and year. E.G. 'January 2018'.
What would be the best way of doing so using PHP?
Try using the strtotime function to turn your string into a timestamp and the date function with the F Y format to get what you want:
$date = "2018-01-01";
$formatted = date("F Y", strtotime($date));
This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 5 years ago.
I'm having a date format like this:
2010-09-21T00:00:00+03:00
how can i convert it to 'Y-m-d H:i:s' format?
I've tried following code but I don't think it's working:
$date = new DateTime('2010-09-21T20:00:00+03:00');
$status_date = $date->format('Y-m-d H:i:s');
It prints time like this: 2010-09-21 20:00:00
It prints exactly want you want ! So what's wrong ?
You can also use Carbon and to like this :
Carbon::parse('2010-09-21T00:00:00+03:00')->toDateTimeString();
UPDATE
Be careful, you said you want midnight but you wrote 8pm in your php !
This question already has answers here:
Convert one date format into another in PHP
(17 answers)
Closed 6 years ago.
How can I change the format of my date from 2016-10-05 to 10/05/2016 in php
$date= $row['date'];
So when the row echos out it'll all be the new format
Use DateTime to create an object (from the current format), allowing you to reformat the output.
$date = "2016-10-05";
$date = DateTime::createFromFormat('Y-d-m', $date);
echo $date->format('d/m/Y');
https://repl.it/DqvO
This question already has answers here:
How to get GMT date in yyyy-mm-dd hh:mm:ss in PHP
(6 answers)
Closed 6 years ago.
I am using mssql db with php. Which PHP function can return the current datetime. (i.e.) I want the current date and time to be saved in the following format say for example,
2016-07-04 11:10:05.000
Thanks!
Use date->format http://php.net/manual/it/function.date.php
$date = new DateTime('2000-01-01');
echo $date->format('Y-m-d H:i:s.u');
12-hour format
date("Y-m-d h:i:s.u")
24-hour format
date("Y-m-d H:i:s.u")
With "date" you can format the output and with "time" you get the current unix time.
Example
echo date("Y-m-d H:i:s.u", time());
Documentation: http://php.net/manual/it/function.date.php
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
PHP: convert date format yyyy-mm-dd => dd-mm-yyyy [NOT IN SQL]
Right now I have DATE stored in mysql as : YY-MM-DD. EX: 2011-12-22.
How can I convert using strtotime to MM-DD-YY in php?
$originalDate = "2010-03-21";
$newDate = date("d-m-Y", strtotime($originalDate));
or use the following link for the similar question
Convert date format yyyy-mm-dd => dd-mm-yyyy