RIAS
asked on
Filter sql on date and time
Hello ,
I have a query which filters on date
How can I filter on date and time.
The requirement is that : WHERE (([Date Time] >= ''' + CAST(@SelectedDateTime AS NVARCHAR(24)) + ''') and also the time .
Check the time now and display records which are from time.now.
Example;
Time now is 11:30 ; display records from 11:30 onwards .
Regards
I have a query which filters on date
SELECT
[Job #]
, [Date Time]
, Car
FROM tableA
WHERE (([Date Time] >= ''' + CAST(@SelectedDateTime AS NVARCHAR(24)) + ''')
OR (Car = '''')
OR (Driver = '''')) '
How can I filter on date and time.
The requirement is that : WHERE (([Date Time] >= ''' + CAST(@SelectedDateTime AS NVARCHAR(24)) + ''') and also the time .
Check the time now and display records which are from time.now.
Example;
Time now is 11:30 ; display records from 11:30 onwards .
Regards
If you just want >= 11:30 then you can use below-
Explanation - First get the date and add your time in there and add that in the filter condition.
For range you can use above comment.
Explanation - First get the date and add your time in there and add that in the filter condition.
For range you can use above comment.
DECLARE @SelectedDateTime AS DATETIME = GETDATE()
SET @SelectedDateTime = CAST(CAST(CAST(@SelectedDateTime AS DATE) AS VARCHAR(10)) + ' 11:30:00' AS DATETIME)
SELECT
[Job #]
, [Date Time]
, Car
FROM tableA
WHERE (
(
[Date Time] >= '''' + CAST(@SelectedDateTime AS NVARCHAR(24)) + ''''
)
OR (Car = '''')
OR (Driver = '''')
)
ASKER
Thanks Pawan,
I really do not need 11:30:00. I need the time now and then filter any suggestions?
I really do not need 11:30:00. I need the time now and then filter any suggestions?
ASKER
Can i have date.time ot time.now. Any suggestions on syntax?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks! will try and brb
cool.
ASKER
Worked liked Charm mate!!
ASKER
Thanks a lot!
welcome. Cheers :)
Please use like below -
Open in new window