Jump to content

[SOLVED] date and time help needed.


spires

Recommended Posts

Hi guys.

 

I have a date and time stored in my database: 24/06/2009 09:41:26

 

What I need to be able to do is see how much time has passed.

Example:

Todays date & time - Stored date & time = 01d 05h 58min has passed

 

i'm really stuck on this, does anyone of any date function that can do this?

 

Thanks for your help.

Link to comment
Share on other sites

Hi,

 

Your code works perfect.

However, at the moment it counts down, how do I get it to count up?

 

I want to put in a start date, If I do that in your code, I get -3 days, rather than 3 days.

Please see: http://www.businessmobiles.com/comcalc/test4.php

 

Your code:

$subEnd = date("6/22/2009 11:08:30");

$timeLeft = (strtotime($subEnd) - time());
$mins = floor($timeLeft / 60);
$secs = $timeLeft - ($mins * 60);

$hours = floor($mins / 60);
$mins = $mins - ($hours * 60);

$days = floor($hours / 24);
$hours = $hours - ($days * 24);

echo "You have {$days} days, {$hours} hours, {$mins} minutes and {$secs} seconds remaining of your subscription";

 

 

Thanks

Link to comment
Share on other sites

Firstly, you should store your date-time values in a DATETIME type field (YYYY-MM-DD HH:MM:SS). As far as I know the MySQL functions doesn't recognize your current format, and I know that strtotime() doesn't. Alternatively you'd have to rearrange your format into the above format:

 

$old_format = '24/06/2009 09:41:26';
$parts = explode(' ', $old_format);
$parts[0] = implode('-', array_reverse(explode('/', $parts[0])));
$new_format = implode(' ', $parts);

 

Then you could use Russell's code, but rearrange strtotime($subEnd) - time() into time() - strtotime($subEnd), where $subEnd is the date-time value.

Link to comment
Share on other sites

thebadbad beat me to the punch, I was gonna say to switch those values, however, I was bickering with newegg, do you believe they don't let you use alternative mailing addresses with paypal.. so now I need to wait 5 freaking days for a refund!!!!! argh!! so aggravating!! but, what can I do, they gave me a $5 discount on my next purchase.. I'll use the money I save @ the pump.. and get 2 gallons of gas ahahaha..

Link to comment
Share on other sites

Solved. Thanks guys :)

 

$subEnd = date("m/d/Y H:i:s");

$timeLeft = (strtotime($subEnd) - strtotime($notes_date));

$mins = floor($timeLeft / 60);
$secs = $timeLeft - ($mins * 60);

$hours = floor($mins / 60);
$mins = $mins - ($hours * 60);

$days = floor($hours / 24);
$hours = $hours - ($days * 24);

$diffDate = "{$days}d, {$hours}h, {$mins}min";

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.