Jump to content

date conversion function


nmcabe

Recommended Posts

I am working on a project where I need PHP and mysql to perform calculations on dates, so I am storing them in the mysql format 2011-09-12, I am writing a custom function that will convert this into a date('M d Y') format, but all I get when I run my function is "1" This is my first custom function, so i am sure it is a simple fix, I am just at the end of my spectrum on functions. I can do this as an inline script, but will need this on various pages

function readableDateConvert($mysqlTime)	{
$phpTime = strtotime($mysqlTime);
$readableTime = date('M d Y',$newTime);
return $readableTime;
}	

Link to comment
https://forums.phpfreaks.com/topic/246970-date-conversion-function/
Share on other sites

You haven't defined $newTime.  Turn on error reporting and you will get a notice for that. Plus you are just formating it for the year:

 

function readableDateConvert($mysqlTime) {
   return date('M d Y', strtotime($mysqlTime));
}

You haven't defined $newTime.  Turn on error reporting and you will get a notice for that. Plus you are just formating it for the year:

 

function readableDateConvert($mysqlTime) {
   return date('M d Y', strtotime($mysqlTime));
}

While I was trying to get it to work, I changed some variable names and made this mistake, I did have it defined before I posted this, however your much shorter method of doing things than mine worked perfect, thank you so much for your time, here is my final working code

function readableDateConvert($mysqlTime)	{
return date('M d Y', strtotime($mysqlTime));
}	

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.