Jump to content

Working with times stored with one separate date.


arrayGen

Recommended Posts

It would probably be helpful if you posted what data you do have and what result you are trying to accomplish. It sounds like a date and two times per row? What format is the date and what format is the time?

 

 

the super twats from the super companies all use

 

start: 11::00:00

end: 00:00:00

date: 2011-01-01

 

you can see the apparent failure here. ??? can you ?

Link to comment
Share on other sites

the super twats from the super companies all use

 

start: 11::00:00

end: 00:00:00

date: 2011-01-01

 

you can see the apparent failure here. ??? can you ?

 

I don't think you should be throwing derogatory names around like that. Because as arrayGen just alluded to, it seems YOU are the only one that doesn't see the obvious solution:

 

Combine the date with each time - individually - to come up with two timestamps! Although your example is in error since the end time is before the start time. 00:00:00 is the beginning of a day not the end of a day. So, in reality your two timestamps should be

 

Start timestamp: 2011-01-01 11:00:00

End timestamp: 2011-02-01 00:00:00

Link to comment
Share on other sites

the super twats from the super companies all use

 

start: 11::00:00

end: 00:00:00

date: 2011-01-01

 

you can see the apparent failure here. ??? can you ?

 

I don't think you should be throwing derogatory names around like that. Because as arrayGen just alluded to, it seems YOU are the only one that doesn't see the obvious solution:

 

Combine the date with each time - individually - to come up with two timestamps! Although your example is in error since the end time is before the start time. 00:00:00 is the beginning of a day not the end of a day. So, in reality your two timestamps should be

 

Start timestamp: 2011-01-01 11:00:00

End timestamp: 2011-02-01 00:00:00

 

yes Sherlock, but what im trying to say is, the times are stored as

 

start: 11::00:00

end: 00:00:00

date: 2011-01-01

 

but how would you manipulate this to correct it ?

 

strtotime(date("Y-m-d H:i:s", "{end} {date}")) - strtotime(date("Y-m-d H:i:s", "{start} {date}"))

 

will cause a minus time , this is true but how do we rectify this what would be the best angle of attack.

 

 

Link to comment
Share on other sites

Why do you see the need to resort to name calling?

 

What was not clear in the previous posts was that the end time may - intentionally -  be less than the start time. If that is the case, then I would assume that the end time is for the next day.

 

So the solution is simple. If the end time is before the start time, then increment the end date to +1 days.

$start_time = "11:00:00";
$end_time = "00:00:00";
$date = "2011-01-01";

$start_timestamp = strtotime("{$date} {$start_time}");
$end_timestamp = strtotime("{$date} {$end_time}");
//Check if end time is before start time
if($end_timestamp < $start_timestamp)
{
    //Adjust end date to next day
    $end_timestamp = strtotime("{$date} {$end_time} +1 days");
}

echo "Start date/time: " . date('m-d-Y H:i:s', $start_timestamp);
echo "<br />End date/time: " . date('m-d-Y H:i:s', $end_timestamp);

//Output
//Start date/time: 01-01-2011 11:00:00
//End date/time: 01-02-2011 01:00:00

Link to comment
Share on other sites

Why do you see the need to resort to name calling?

 

What was not clear in the previous posts was that the end time may - intentionally -  be less than the start time. If that is the case, then I would assume that the end time is for the next day.

 

So the solution is simple. If the end time is before the start time, then increment the end date to +1 days.

$start_time = "11:00:00";
$end_time = "00:00:00";
$date = "2011-01-01";

$start_timestamp = strtotime("{$date} {$start_time}");
$end_timestamp = strtotime("{$date} {$end_time}");
//Check if end time is before start time
if($end_timestamp < $start_timestamp)
{
    //Adjust end date to next day
    $end_timestamp = strtotime("{$date} {$end_time} +1 days");
}

echo "Start date/time: " . date('m-d-Y H:i:s', $start_timestamp);
echo "<br />End date/time: " . date('m-d-Y H:i:s', $end_timestamp);

//Output
//Start date/time: 01-01-2011 11:00:00
//End date/time: 01-02-2011 01:00:00

 

your still unsure, mr self proclaimed guru, who invented guru ? and mogul ?

Link to comment
Share on other sites

Why do you see the need to resort to name calling?

 

What was not clear in the previous posts was that the end time may - intentionally -  be less than the start time. If that is the case, then I would assume that the end time is for the next day.

 

So the solution is simple. If the end time is before the start time, then increment the end date to +1 days.

$start_time = "11:00:00";
$end_time = "00:00:00";
$date = "2011-01-01";

$start_timestamp = strtotime("{$date} {$start_time}");
$end_timestamp = strtotime("{$date} {$end_time}");
//Check if end time is before start time
if($end_timestamp < $start_timestamp)
{
    //Adjust end date to next day
    $end_timestamp = strtotime("{$date} {$end_time} +1 days");
}

echo "Start date/time: " . date('m-d-Y H:i:s', $start_timestamp);
echo "<br />End date/time: " . date('m-d-Y H:i:s', $end_timestamp);

//Output
//Start date/time: 01-01-2011 11:00:00
//End date/time: 01-02-2011 01:00:00

 

your still unsure, mr self proclaimed guru, who invented guru ? and mogul ?

 

what layer of the application would you tackle this problem in ? only an idiot would do it like that

Link to comment
Share on other sites

what layer of the application would you tackle this problem in ? only an idiot would do it like that

 

You did post this in the PHP forum, right? So it is only logical that you were looking for a PHP solution. If you wanted a database or other type of solution you should post in the appropriate forum.

Link to comment
Share on other sites

what layer of the application would you tackle this problem in ? only an idiot would do it like that

 

You did post this in the PHP forum, right? So it is only logical that you were looking for a PHP solution. If you wanted a database or other type of solution you should post in the appropriate forum.

 

not too sharp today are we Jaldinder Gee

Link to comment
Share on other sites

So is your theory for the best way to get help to be a jerk?

 

You're here looking for a solution to what is frankly a simple problem, and though you didn't have enough programming acumen  to solve the issue yourself, you're bright enough to critique the code?

 

Classic

Link to comment
Share on other sites

So is your theory for the best way to get help to be a jerk?

 

You're here looking for a solution to what is frankly a simple problem, and though you didn't have enough programming acumen  to solve the issue yourself, you're bright enough to critique the code?

 

Classic

 

i solved it way before you guys did, your slow as hell.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • 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.