Jump to content

time calculation!


robcrozier

Recommended Posts

Hi,

 

what i'm trying to do is add a given duration (as supplied by a user via a form field) - i.e. 3days, to the current time.

 

So basically, i want to take the current time, add the specified duration to it (e.g. 3 days) and then return the output date in this format: Y-m-d H:i:s.

 

I'm getting really confused and just can't figure it out.  Here's what i'm currently using, though it's outputting completely the wrong date+time.

 


$current_time = date('Y-m-d H:i:s');
$duration_timestamp = $duration * 86400; 
$now = convert_datetime_db_format($current_time); // function that converts to timestamp 
$end_datetime = $now + duration_timestamp;
$end = date('Y-m-d H:i:s', $end_datetime); // final date = WRONG!!!

 

Any help appreciated!  cheers!

Link to comment
Share on other sites

this is simple to do.

 

Make sure

 

<?php
$current_time = time();
$duration_timestamp = $duration * 86400; // Amount of days in Seconds (Correct)
$end_datetime = $current_time + $duration_timestamp;
$end = date('Y-m-d H:i:s', $end_datetime); // final date
?>

 

hope this helps. (time() function gives the current unix timestamp)

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.