Could do with some help with the following problem.
I have extracted a date from a datetime field in a mysql database (yyy-mmm-ddd hh:mm:ss) held in f_date
and the result displays
echo $info['f_date'];
2009-11-14 12:00:00
however I would also like to display this date plus a variable amount of hours
eg
echo $info['f_date'] +5 hours;
2009-11-14 17:00:00
I have no idea how to go about this as it seems there is incompatability between PHP and mySQL formats
What I would like is a fix so I can complete the problem and a pointer to where to look so I can understand whats going off.
Thanks in advance
PHP mySQL newbie date calculation advice!
Moderator: General Moderators
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: PHP mySQL newbie date calculation advice!
date() and strtotime() are great:
Code: Select all
echo date("Y-m-d H:i:s", strtotime('+5 hours', strtotime($info['f_date'])));
//or
echo date("Y-m-d H:i:s", strtotime($info['f_date'])+18000);
Last edited by AbraCadaver on Wed Dec 16, 2009 1:40 pm, edited 1 time in total.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: PHP mySQL newbie date calculation advice!
thanks thats great and I now know where to investigate further, the only slight problem that isnt much of a problem is that one date is dashed and the other is slashed. Could use string replace
eg
2009-11-10 12:00:00 2009/11/11 22:00:00
thanks again
great forum
eg
2009-11-10 12:00:00 2009/11/11 22:00:00
thanks again
great forum
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: PHP mySQL newbie date calculation advice!
My mistake. Just change the date('format'). I edited it in my post above.glow777 wrote:thanks thats great and I now know where to investigate further, the only slight problem that isnt much of a problem is that one date is dashed and the other is slashed. Could use string replace
eg
2009-11-10 12:00:00 2009/11/11 22:00:00
thanks again
great forum
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.