Jump to content

sprintf output for date format


turpentyne

Recommended Posts

I'm trying to figure out how to get this to generate the date field pulled from a query that pulls a datetime field called "date". But It's just giving me some default:

12/31/69 7:00 PM

 

$Output .= sprintf ($ExpandImageTemplate, htmlspecialchars ($row['title']),htmlspecialchars ($row['content']),htmlspecialchars ($row['img_url_small']),htmlspecialchars ($row['img_url_large']),htmlspecialchars ($row['deck']),date("m/d/y g:i A",($row['date'])));

Link to comment
https://forums.phpfreaks.com/topic/267978-sprintf-output-for-date-format/
Share on other sites

Without looking at your code, if you're getting that date it means that the "timestamp" value you gave to some date function (like date() or strtotime()) is invalid. Or very small. Like

date("Y-m-d H:i:s", "September 4th 2012, 12:30 am") // 1969-12-31 HH:00:00

You have date("m/d/y g:i A",($row['date'])).

 

The second argument to date is expected to be an integer containing the Unix timestamp for the date and time you want to format.  You're most likely passing it an already formatted date string.  Depending on the format of this date string, it might be sufficient to simply use strtotime to convert it into a Unix timestamp before re-formatting with date.

 

date('m/d/y g:i A', strtotime($row['date']))

 

However, strtotime cannot make sense of every possible date/time string.  If the above does not work, show us the value for $row['date'] as there are other alternatives available for when strtotime does not work.

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.