date() function format question/problem

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
Fran3
New php-forum User
New php-forum User
Posts: 4
Joined: Sun Oct 08, 2017 4:01 pm

Sun Nov 19, 2017 9:09 am

I've written a function to return the: DayName mm-dd-yyyy

It works with input format as "10:30pm April 15 2014"

The Question: How to get it to work with input format as "2013-01-10 00:00:00"
as this is the value returned from the date field in the record I'm working with.

Code Below - Thanks for any help !

Code: Select all

function date2day_mdy($date2fix) {
	$date_fixed = date("D m-d-Y",$date2fix);
	return $date_fixed;
}
$d=strtotime("10:30pm April 15 2014"); // works - yes
//$d=strtotime)"2013-01-10 00:00:00"); // works - no
$returned_date = date2day_mdy($d);
echo $returned_date."<br>";

User avatar
benanamen
New php-forum User
New php-forum User
Posts: 23
Joined: Mon Oct 16, 2017 1:06 pm

Sun Nov 19, 2017 10:50 am

If you are pulling the date from a Database there is no need for the code gymnastics. Just ask the DB to give it to you the way you want it.

Code: Select all

SELECT DATE_FORMAT(date_column, '%m-%d-%Y') FROM table
The XY Problem
The XY problem is asking about your attempted solution (X) rather than your actual problem (Y). This leads to enormous amounts of wasted time and energy, both on the part of people asking for help, and on the part of those providing help.

Fran3
New php-forum User
New php-forum User
Posts: 4
Joined: Sun Oct 08, 2017 4:01 pm

Sun Nov 19, 2017 1:40 pm

Ah Ha !
Thanks :-)

Post Reply