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
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));
}

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));
}	

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.