/    Sign up×
Community /Pin to ProfileBookmark

Edit format iserted by NOW()

Hi there,
Im inseting NOW into my SQL database which gives me the date and time.. How can i edit it so that is stored or shows something like.. Tuesday 6 March, 15:35

Cheers,
Scott

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@chazzyOct 23.2006 — you don't and you shouldn't (and I don't care what anyone says after i post this). ?

When you store something in the database, you store data, you don't store a format.

you can format data on retrieval (via select) but you shouldn't format your data on the way in.

in mysql, you can use the date_format function to format date/times as they come out of the database.

http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html
Copy linkTweet thisAlerts:
@NogDogOct 23.2006 — Also, make sure the field into which it is being stored is defined as a datetime type.
Copy linkTweet thisAlerts:
@pcthugOct 23.2006 — Try something like this, only substitute the current value for [FONT=Courier New]$subject[/FONT] with the retrieved database [FONT=Courier New]NOW()[/FONT] value:[code=php]
$subject = date('Y-m-d H:i:s');
$t = preg_split('/[-: ]/', $subject);
echo date('l j F, H:i', mktime($t[3], $t[4], $t[5], $t[1], $t[2], $t[0]));
[/code]
×

Success!

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