Jump to content

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.

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.