Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Query with Long Date Time?

Tags:

c#

sql

datetime

I am trying to pass a SQL query through c# , currently it is based on just the day month and year with time always set to 0 EG 1997-10-28 00.00.00.000 which is great as the time never changes it easy for me to just Select Where date equals the calendar date.

However with the Start Field , the time is different on each record , eg 1899-12-30 14.14:00.00.000 , 1899-12-30 15.14:30.00.000 . (Seconds downwards are always the same) .

So I need to have a query that will return all the results of the selected date on the "Start" field . How would I do this?.

E.G IF i click the calendar which passes 1997-10-28 00.00.00.000 , I would like the results of every time in that day!. How do I go about that?.

Thanks for any input.

EDIT: Is there a way to format the date that i have in SQL ?. This comes from an old access database!. and as you can see above it is 1899-12-30 ?. not 1998 , I don't know why this has happened!.

like image 456
user685590 Avatar asked Mar 30 '26 17:03

user685590


2 Answers

WHERE DATEDIFF(dd, your_start_field, @your_param) = 0
like image 123
LukeH Avatar answered Apr 01 '26 08:04

LukeH


You need to select all record between today and tomorrow without including tomorrow's date.

WHERE EventDate >= StartDate AND EventDate < DATEADD(d, 1, StartDate)
like image 38
Leons Avatar answered Apr 01 '26 09:04

Leons