date_format

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

date_format

Post by Jim_Bo »

Hi,

Can you add gmt +9 on a statement like so?

Code: Select all

date_format(date, '%d/%m/%y %r') as date,

Thanks
Last edited by Jim_Bo on Fri Feb 18, 2005 7:38 am, edited 1 time in total.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

use strtotime()
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post by Jim_Bo »

Hey,

Should something like this work .. to add 14 hours to the date/time that was input using now() held in the database:

Code: Select all

SELECT id, date_format('%d/%m/%y %r', date_add(date, interval 14 hours)) as date, ...
Thanks
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

Have YOU tried this.
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post by Jim_Bo »

Hi

Do you mean have I tried it .. ?


Yer it gives a check syntax error ..
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

Yer it gives a check syntax error ..
:lol:
PHP way

Code: Select all

//suppose $date contains db stored date
//then reqd. date will be
$reqdDate = strtotime($date . " + 14 hours " );
and for MySQL remove 's' from hours as there is no hours only H O U R :wink:
Jim_Bo
Forum Contributor
Posts: 390
Joined: Sat Oct 02, 2004 3:04 pm

Post by Jim_Bo »

Hi,

I got it .. here is the code im sure it will come in handy for people .. clean way to add/subtract GMT and display the date and time in a nice formated result ..

Sql code:

Code: Select all

SELECT id, DATE_FORMAT(ADDDATE(date, INTERVAL 18 HOUR), '%d-%b-%Y %r') AS date, ..
Thanks
Post Reply