Jump to content

Recommended Posts

I started a mysql database, with the following field being pertinent:

 

dtg_start -- Stores the value of $dtg_start=date("m/d/Y_H:i:s", time());... This returns "04/17/2010_13:01:00"

 

In my inexperience, I didn't store the UNIX epoch value, for functions like this... SO, without re-doing my database to include a "dtg_unix_start" field, then doing "then"-"now" (987654321-123456789) and converting the resulting UNIX time into "human time", is there a way to format now() into the same format, then use the "strtotime" feature to "subtract" strings from each other?

 

Essentially, when a person is entered into the database, it timestamps their entry in the dtg_start field. I have a "view status" page that is a table that shows timestamp, then the person's information. I want to add an "Elapsed" field next to the timestamp to show how long the person has been in the system.

 

 

I've read a little on the strtotime function, and it seems to be problematic, espicially when it comes to the last day of the month. Any ideas? (Or just suck it up and re-do the database? lol)

 

 

Thanks!

Mysql has a couple of dozen built in data/time functions that you can use to do just about anything with a DATE or DATETIME value. No slow parsed, tokenized, interpreted php code is needed for most things.

 

You can convert your exiting data into a DATETIME by using the mysql STR_TO_DATE() function in a query. You can also retrieve a DATETIME in any format using the msyql DATE_FORMAT() function in your queries.

Ok, changed the database... added a u_start (UNIX_start) field...

 

 

Put the following code into my PHP file to display the elapsed time..

 

$x_now = time();
$elapsed = $x_now-$row[21];
$elapsed = date("h:i:s", $elapsed);

(example) echo "$elapsed";

 

 

The minutes/seconds are right, but it shows 6:04:32.. why 6 hours? is this a result of my timezone (Eastern US) and DST? Do i need to specify somewhere what timezone, even though I'm working off both UNIX epoch timestamps??

 

UGH

 

 

The UNIX time stamp is relative to local server time. Verify your clock source on the server as well as its configured time zone. You can also specify the timezone in the date() function. It should calculate Daylight Savings based on the date.

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.