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
Solved

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

Posted on 2013-12-17
4
622 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mysql ide 10 44
mysql db 3 69
subtr returning incorrect value 8 29
Using PhpMyAdmin (or Mysql) for a find and replace operation 11 12
Read about achieving the basic levels of HRIS security in the workplace.
As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
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…

860 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