/    Sign up×
Community /Pin to ProfileBookmark

Hi

In a mysql table I have the date and time stored a 2007-08-18 00:00:00 which is set by the datetime format.

I know how to get the date out of it using the explode function as I want the reorganize the, how would I get the time from the cell so that I can re organize it,

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@kprocauthorAug 20.2007 — I want to return a string like

august 19 at 3:30pm from the information stored in the mysql table
Copy linkTweet thisAlerts:
@Declan1991Aug 20.2007 — Well firstly you need an array of the months that correspond to the 01 to 12 section of the date. Then you need to get the appropriate variable out of the exploded string, and use it as the index to get the month in text. Then you need to add the appropriate parts of the exploded date to it.

Something like this:
[code=php]
$result = "2007-08-18 00:00:00";
$months = array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
$split = explode(" ",$result);
$dte = explode("-",$split[0]);
$tme = explode(":",$split[1]);
$ap = ($tme[0] > 11)?"am":"pm";
$tme[0] = ($tme[0] > 11)?$tme[0]:$tme[0]-12;
$rdte = "$months[$dte[1]]$dte[2] at $tme[0]:$tme[1] $ap";
[/code]

$rdte is the result, $result is the date from the database.
×

Success!

Help @kproc 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,
)...