Jump to content

Using strtotime to add to a time


HarryMW

Recommended Posts

Little confuzzled.

 

I have got a bunch of listings that will be printed at the end of the page but I need to subtract a time specified in a textbox (send it to itself) on the page.

 

$row['active'] = (strtotime('$row[etd]') + $rwy1 = $_POST['tmatttextfield']);

Well this just converts the time in the database which is always going to be a four character number such as: 1300 for 1PM into a time and adds the textbox value to the time.

 

<td width="50" bgcolor="<?php echo $bc?>"><strong><?php echo date('hi', $row['active']);?></strong></td>

That just prints it all out formatting the time to only Hours and Minutes.

 

So just to clarify the user would put in say '10' in the textbox which would constitute 10 minutes.

The code above should then define that '10' as 10 minutes.

Define the database result, ie. 1500 as 3PM and add the 10 minutes to it so it would become 1510.

 

I have been getting some wierd and wonderful results whilst trying to get it to work. Mainly just 1200 though.

 

Harry.

Link to comment
Share on other sites

No news? Just to clarify.

 

A typical database entry would be 1500. (3PM)

A typical text field entry would 10 or even 00:10:00 (H:M:S)

 

I would like to plus the text field entry onto the database entry. So it would become 1510.

 

Harry.

 

 

Link to comment
Share on other sites

I think if you just do something like this it could work:

 

$timetoadd = "10"; //from your text field
$time = "1500"; //from database

$newtime = date('Hi', strtotime($time." +".$timetoadd." minutes"));

 

I couldn't get it to work with something like 00:10:00 for some reason, but this is the concept. You can do +10 minutes, hours, months, years, etc.

 

Note: I used 'Hi', not 'hi' because lower-case h is 12-hour time, so you would get 0310.

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.