Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Need to add 8 hours to a MySQL DATETIME

Enthusiast ,
Apr 01, 2013 Apr 01, 2013

I'm using PHP and I need to add 8 hours to a DATETIME column in my DB. I want to be able to create a time limit for a user to edit an entry they've entered in my DB.

For example, I would like to hide a button [something like: show if datetime <= NOW()] which prevents me going update page once the deadline has expired...

The code I have in my insert behaviour is this:

.$_POST['fld_vLOCKDATE'] = date('Y-m-d H:i:s').

and I am trying to create something like this:

.$_POST['fld_vLOCKDATE'] = date('Y-m-d H:i:s' + 'INTERVAL 8 HOURS').

or

.$_POST['fld_vLOCKDATE'] = date('Y-m-d H:i:s +8 HOURS').

but I am just getting records with 0000-00-00 00:00:00

If I use the following code, then the current time is posted, not 8 hours in front:

.$_POST['fld_vLOCKDATE'] = date('Y-m-d H:i:s, INTERVAL 8 HOURS').

Any thoughts as to what I am doing wrong? In fact, if you've got any thoughts on another way I can attack it, then I'd welcome those suggestions too. I did think about using a timestamp and then: "saying show if TIMESTAMP <= 8 hours old" but my computer don't get plain English, and I obvoiulsy don't talk good computer!

Thanks.

TOPICS
Server side applications
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Apr 01, 2013 Apr 01, 2013

You're trying to mix PHP functions with MySQL ones. This should do the trick:

$_POST['fld_vLOCKDATE'] = date('Y-m-d H:i:s', strtotime('+ 8 hours'));

Translate
LEGEND ,
Apr 01, 2013 Apr 01, 2013

You're trying to mix PHP functions with MySQL ones. This should do the trick:

$_POST['fld_vLOCKDATE'] = date('Y-m-d H:i:s', strtotime('+ 8 hours'));

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 01, 2013 Apr 01, 2013
LATEST

Thank you David. Much appreciated.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines