Jump to content

Time Question


Hate

Recommended Posts

I need to create some sort of queuing system for my php application to function properly. I was just going to a simple one with a column named "enqueued" and have a queued table that has id, start_time, stop_time. It's more like an ordered "delayed" queue system.. eh whatever.

 

Anyways, what would be the best way to store and access the times in the database? I'm supposing I can just use a TIMESTAMP and have the default value set to TIMESTAMP for the start_time, how how about stop_time I'm assuming still a TIMESTAMP, but with no default value and it can't be null.

 

But, how would I do the time in php? Like adding an amount to a timestamp.. and is there any special functions I can use to read the results from the mysql timestamp fields? Let's say I wanted to take a timestamp of now and add 40 minutes to it.. how do I do this?

Link to comment
Share on other sites

I'm not sure I understand what you are asking.  I get the first two statements, but the last one kinda fogs my brain.

 

To add an amount to a timestamp in PHP.

<?php
$timestamp = time(); //or you could set this to any timestamp you want to. 
echo date('m-d-Y h:i:sa',strtotime('+40 Minutes',$timestamp)); //gives you 40 minutes into the future.
?>

 

To set a timestamp column in MySQL for 40 minutes into the future, you could do.

 

<?php
$sql = "UPDATE times SET timestamp_column=DATE_ADD(NOW(),INTERVAL 40 MINUTE) WHERE id='1'";
?>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.