Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL Dates misery...

Status
Not open for further replies.

Ayac

Programmer
Nov 10, 2000
141
HU
Hi All!

I am trying to move my Access tables into MS SQL Server. I have Time and Date in separate columns in Access. Now I put them all together into one DateTime field. I also have a calendar progam what suppose to display only those events what are happening today.
Now I need to create a query that will list all those events that are just a few hours long or take an entire week so it has to be indicated on today's list. How can I do that on a very elegant way? It was easy in Access because I kept the Date values in a separate table so I could use <= =< to set up a range of date values... but SQL has to have everything in one field...
 
Well,

you could use the datepart function,
example:

SELECT DATEPART(year, GETDATE())
SELECT DATEPART(month, GETDATE())
SELECT DATEPART(day, GETDATE())
SELECT DATEPART(hour, GETDATE())




 
Thanks! We actually figured out in the meantime. It is a little more complex, we also need to use CAST with '/'-es and the DATEPART Month/Day/Year AS DateTime so the interpreter will handle the pieces as a DateTime variable for comparison.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top