Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

set date as 23:59:59 pm instead of 12 am

Posted on 2013-12-17
4
Medium Priority
?
644 Views
Last Modified: 2013-12-17
I am sending a date variable for start time and end time
The start time is find being automatically set to 12 am
However I need to end date to be set to 23:59:59

below are the code fragments that address the date:


 IN fromDate varchar (50),
        IN toDate varchar (50),
        IN timeZone varchar (50))

    BEGIN
            DECLARE startDate varchar (50);
            DECLARE endDate varchar (50);
            DECLARE mylogID Int;

             SET startDate = FROM_UNIXTIME(fromDate/1000);
             SET endDate = FROM_UNIXTIME(toDate/1000);

time_to_sec(timediff(endDate, startDate)) / 3600 AS totalTimeRange

Open in new window

0
Comment
Question by:portlight
[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
  • Learn & ask questions
  • 2
4 Comments
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39725808
I don't get it. 12 am is 00:00:00. Why do you need the end time to be a second before start time?
0
 

Author Comment

by:portlight
ID: 39725814
If the start date is 1/4/2014 the time always is 00:00:00
If the end date is 1/6/2014 the time is always 00:00:00
 
There 23 hours, 59 minutes and 59 seconds left in the 1/6/2014 day that are exlcuded from the range difference.
so I need the range to be midnight of the start date to 23:59 on the end date
NOT midnight to midnight - leaving out a full day.
0
 
LVL 35

Accepted Solution

by:
Dan Craciun earned 2000 total points
ID: 39725832
Well, replace
time_to_sec(timediff(endDate, startDate)) / 3600 AS totalTimeRange

with
time_to_sec(timediff(DATE_ADD(endDate, INTERVAL 1 DAY), startDate)) / 3600 AS totalTimeRange

This will add a day to your endDate, effectively putting you within 1 sec of your target time.

HTH,
Dan
0
 
LVL 9

Expert Comment

by:QuinnDex
ID: 39725852
how are you storing end date, for the time to be 00:00:00 it would indicate you are storing date only, that works for start date but for end date you need to store date and time, you can hard code the 23:59:59 into the code.

so you would store date and time in this format "2014/01/06 23:59:59"
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
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

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question