/    Sign up×
Community /Pin to ProfileBookmark

convert MySQL date to get day of week

Is there a way to take a MYsql date in the format of YYY-mm-dd and convert it into the format of something like “Monday, June 6”. If there is a way, could someone please post the script, I am stumped on this one.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJun 08.2005 — <i>
</i>SELECT DATE_FORMAT(<span><code>date_column</code></span>, '%W, %M %e') FROM <span><code>table_name</code></span>;

See http://dev.mysql.com/doc/mysql/en/date-and-time-functions.html for more info.
Copy linkTweet thisAlerts:
@rbailerauthorJun 08.2005 — Hey thanks for the help, i didnt know it was that easy. I'm now trying to put the date back into MYsql format and I tried this. Am I close?

mysql_query("UPDATE Shipping SET ship_date = DATE_FORMAT($shipdate, '%Y-%M-%d') WHERE orderid= '$oid' ");
Copy linkTweet thisAlerts:
@NogDogJun 08.2005 — No, the first parameter to DATE_FORMAT() needs to be a mysql date already.

Maybe you want to get both formats in your query, then use whichever you need depending on the situation:
[code=php]
$query = "SELECT date_col AS date_mysql, DATE_FORMAT(date_col, '%W, %M %e') AS date_text FROM table_name";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result))
{
echo "<p>MySQL format date: {$row['date_mysql']}</p>n";
echo "<p>Text format date: {$row['date_text']}</p>n";
}
[/code]
Copy linkTweet thisAlerts:
@rbailerauthorJun 08.2005 — Wow, thanks a lot.
×

Success!

Help @rbailer 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.6,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...