/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Date formating nightmare

I have a mysql date of 1925-02-15. Trying to format it with php code

$birth = date(‘F j, Y’, $date([‘birthDt’]);

It returns “December 31, 1969” everytime for every date.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@CharlesDec 29.2010 — [code=php]$birth = date('F j, Y', strtotime ($date(['birthDt']));[/code]
Copy linkTweet thisAlerts:
@Jarrod1937Dec 29.2010 — To explain charles answer a bit (in case its not obvious), you must feed date() a unix timestamp for it to interpret the date correctly. strtotime does just that (though can do much more). The reason you got December 31, 1969 is that is the beginning of the unix epoch (technically Jan. 1, 1970, the hour and second count for the 1969 date is probably something like 23:59:59).
Copy linkTweet thisAlerts:
@phphelpauthorDec 30.2010 — Thanks guys for the information. The code was just what I needed. One little problem with the code

$birth = date('F j, Y', strtotime ($date(['birthDt']));

The "(" after $date is not needed.
Copy linkTweet thisAlerts:
@eval_BadCode_Jan 02.2011 — [CODE]

CREATE TABLE test (test_date DATE);
INSERT INTO test (test_date) VALUES ('1925-02-15');


SELECT YEAR(test_date), MONTH(test_date), DAY(test_date) FROM test

Output:
Year(test_date), MONTH(test_date), DAY(test_date)
1925, 2, 15
[/CODE]


It might be a little easier to work with this way ?
×

Success!

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