Solved

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

Posted on 2013-12-17
4
614 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
  • 2
4 Comments
 
LVL 34

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 34

Accepted Solution

by:
Dan Craciun earned 500 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
when to use sequences in mysql 4 27
unable to insert record into a table 2 29
FrontEnd tools to create web database application 7 56
Complex MySQL Query 2 16
Read about achieving the basic levels of HRIS security in the workplace.
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

770 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