Click here to Skip to main content
15,891,607 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have Date Column Order_Date In date Time format , I need To Extract Today's Order before 14:00 P:M 'O' Clock and in Second Column I want to extract date from 15:00 P:M till 23:00 P:M in SQL SERVER,

Date Is in 24:00 Hor Format.

What I have tried:

Not Have Idea of date time format
Posted
Updated 16-May-18 4:28am
Comments
OriginalGriff 14-May-18 10:44am    
Try giving us examples of your input and the output you want: any code you have tried yourself would also help a lot to get us to understand what help you need.

Use the "Improve question" widget to edit your question and provide better information.

Your question doesn't make any sense. If the order date/time is before 1400, then the "2nd column" will be null, and vice versa. Besides that, there's the hour between the two times you specified - what about orders between 2 and 3pm?

SQL
SELECT CONVERT(DATEtime,Order_Date,103) AS OrderDate,
       CASE WHEN CONVERT(TIME,CONVERT(DATETIME,Order_Date,103)) <= '14:00' 
            THEN CONVERT(TIME,CONVERT(DATETIME,Order_Date,103)) 
            ELSE NULL 
            END AS before_2pm,
       CASE WHEN CONVERT(TIME,CONVERT(DATETIME,Order_Date,103)) >= '15:00' 
            THEN CONVERT(TIME,CONVERT(DATETIME,Order_Date,103)) 
            ELSE NULL 
            END AS after_3pm
FROM [your_table]


Final note - if you do "not have idea of date format", try googling it and see what you find. If you can't master even the simplest of google searches, you may as well find another line of work.

EDIT ====================================

I modified the code to treat the Order_Date column as a varchar/nvarchar. Once again, googling this would have yielded the answer. If you want to know why you have to write the code that way, google is your friend.
 
Share this answer
 
v9
Comments
Member 13518187 14-May-18 13:44pm    
This is giving an Error as my Order_date Column Is in varchar format and date is getting stored like this in my order_date column '14/05/2018 10:26:15'
Richard Deeming 15-May-18 13:39pm    
Never store dates as varchar! Use one of the Date and time types[^] - eg: datetime2(0)[^].

Not only will it make it easier to query the data, it will also ensure that the values are valid, and reduce the space required to store the values as well.
#realJSOP 16-May-18 9:50am    
I modified my answer to fit your newly revealed requirements.
Hope it will help - work at both version.

SELECT * from TABLE
WHERE FIELDNAME > {ts '2013-02-01 15:00:00.001'}
AND FIELDNAME < {ts '2013-08-05 00:00:00.000'}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900