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
Share on other sites

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.

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.