Solved

# How do I find next day date by end time ?

Posted on 2014-09-29
Medium Priority
314 Views
I have db with these details

``````Title (text)
Date Start Time (Timestamp)
Date End Time  (Timestamp)
``````

I will get input as

``````"This is title"
09/29/2014
11:55 PM
03:35 AM
``````

Now I need to calculate based on end time "03:35 AM".. the next day as "09/30/2014"?

How can I do this?

attached are my sample input screen.
0
Question by:Loganathan Natarajan
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 5
• 3

LVL 111

Assisted Solution

Ray Paseur earned 2000 total points
ID: 40349913
0

LVL 111

Expert Comment

ID: 40349919
Now I need to calculate based on end time "03:35 AM".. the next day as "09/30/2014"?
How do you figure out that the next day is 09/30/2014?  Is this value always the current date + 1 day?  Give us a little more to go on, and I'll be glad to show you the calculations (or just read the article and you'll find many examples of date/time arithmetic).
0

LVL 36

Author Comment

ID: 40350254
Thanks Ray, let me go through your article first.
0

LVL 111

Expert Comment

ID: 40350338
OK.  Once we know the rules for interpreting the times, it should be pretty easy to get the code together.
0

LVL 36

Author Comment

ID: 40351497
I read the tutorial , it is useful and more details to work further. Thanks Ray.

but in my case different, just check the attachment screen. the input comes always one DATE and FROM, TO time ...

So, what is the best way to validate in my case?
doubt.png
0

LVL 111

Accepted Solution

Ray Paseur earned 2000 total points
ID: 40352087
I'll try to show you what I think might work.  Install this script and run it, or test on my server here.
http://iconoun.com/demo/temp_loganathan.php
``````<?php // demo/temp_loganathan.php
error_reporting(E_ALL);
if (!empty(\$_GET))
{
// INTERPRET THE DATES INTO TIMESTAMPS AND ISO-8601 DATETIME VALUES
\$alpha = date('c', strtotime(\$_GET['d'] . ' ' . \$_GET['a']));
\$omega = date('c', strtotime(\$_GET['d'] . ' ' . \$_GET['z']));

// IF THE END DATE/TIME IS EARLIER THAN THE START, ADD A DAY
if (\$omega < \$alpha) \$omega = date('c', strtotime(\$omega . ' + 1 DAY'));

// SHOW THE UNDERSTANDING OF THE DATES
echo "Alpha: \$alpha, Omega: \$omega";
}

// CREATE THE FORM FOR INPUTS
\$form = <<<EOF
<form>
Date:  <input name="d" /><br>
Start: <input name="a" /><br>
End:   <input name="z" /><br>
<input type="submit" value="Go!" />
</form>
EOF;
echo \$form;
``````
0

LVL 36

Author Comment

ID: 40353936
Thanks ray. It is very helpful and fixed it.
0

LVL 111

Expert Comment

ID: 40354228
Great!  Thanks for the points, ~Ray
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
###### Suggested Courses
Course of the Month10 days, 2 hours left to enroll