/    Sign up×
Community /Pin to ProfileBookmark

Time Formatting

Hey guys,

I have this line to query my database:

[code=php]putenv(“TZ=US/Eastern”);
$mySqlDateTime= date(“Y-m-d h:i:s”, time());

// insert values into db
mysql_query(“INSERT INTO messages (name, title, message, postdate) VALUES (‘$_POST[aName]’, ‘$_POST[aTitle]’, ‘$_POST[aMessage]’, ‘$mySqlDateTime’)”);

// and later query results from db
$result = mysql_query(“SELECT id, name, title, message, DATE_FORMAT(`postdate`, ‘%m-%d-%Y at %h:%i:%s’) AS datenow FROM messages ORDER BY id Desc”);[/code]

So when I do:

[code=php]<?php echo $row[‘datenow’]; ?>[/code]

The result is something like: 02-25-2009 at 04:39:39

I’d like the time to read [B]4:39:39pm[/B], but when i change the format to ‘%m-%d-%Y at [COLOR=”Red”]%g[/COLOR]:%i:%s[COLOR=”Red”]%a[/COLOR]‘ it doesn’t do this correctly. It returns g:43:55Wed for some reason.

I guess the FORMAT_DATE doesn’t work with time formatting? I’m lost and can’t figure out any way to make this work correctly.

Does anyone have any idea how I can do this?

Thanks a lot!
-Dan

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@SodbusterFeb 25.2009 — Since there is no &#37;g specifier and %a is for the abbreviated weekday name, I'd say you are getting the expected results. Try "%l:%i:%s%p".

DATE_FORMAT()
Copy linkTweet thisAlerts:
@dtm32236authorFeb 26.2009 — Oh - thanks Sodbuster

I was using PHP sytax:

http://us3.php.net/date

I guess that's not the same as DATE_FORMAT. Anyway, thanks for clearing this up!
Copy linkTweet thisAlerts:
@OctoberWindFeb 26.2009 — DATE_FORMAT is MySQL, thus needing the MySQL format specifiers :-)
Copy linkTweet thisAlerts:
@SodbusterFeb 26.2009 — Third time's a charm, so here's another link identical (except for v.5.0, not 4.1) to my first one: Link
Copy linkTweet thisAlerts:
@dtm32236authorFeb 26.2009 — That clears everything up. Thanks again guys.
×

Success!

Help @dtm32236 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...