•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 329,102 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,512 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser:
Views: 110 | Replies: 1
![]() |
•
•
Join Date: Jul 2005
Posts: 91
Reputation:
Rep Power: 3
Solved Threads: 0
Hey guys,
I am trying to design a query that will return all the records based on a single date but because of the date/time data type in MS SQL 2005 it defaults to the date and the time 00:00:00 which will return no records for me.
Is it possible to ignore the time part in the select statement?
Thanks.
I am trying to design a query that will return all the records based on a single date but because of the date/time data type in MS SQL 2005 it defaults to the date and the time 00:00:00 which will return no records for me.
Is it possible to ignore the time part in the select statement?
Thanks.
•
•
Join Date: Jul 2005
Location: Downingtown
Posts: 45
Reputation:
Rep Power: 3
Solved Threads: 2
Here is the way I deprecate a standard datetime (5/7/2008 23:28) to a smalldate (5/7/2008) in my sql statements:
Cast(Floor(Cast(myDateTimeField as float)) as datetime)
This first converts the datetime field myDateTimeField to a float. The float is an accurate representation of time. I beleive that the computation is based on how many days its been since some date in the past. For instance today it is 39573 days past this past date. If the number returned was 39573.25 I would know that the time value is 6am on the same date. By flooring what the inner cast returns you are chopping off the time from the datetime field, then you cast it back to a datetime in order for it to be a date again. Only this time its 5/7/2008 00:00:00. This is the best way I know of to remove time from a datetime when performing date arithmetic / applying date logic.
Hope this helps.
Cast(Floor(Cast(myDateTimeField as float)) as datetime)
This first converts the datetime field myDateTimeField to a float. The float is an accurate representation of time. I beleive that the computation is based on how many days its been since some date in the past. For instance today it is 39573 days past this past date. If the number returned was 39573.25 I would know that the time value is 6am on the same date. By flooring what the inner cast returns you are chopping off the time from the datetime field, then you cast it back to a datetime in order for it to be a date again. Only this time its 5/7/2008 00:00:00. This is the best way I know of to remove time from a datetime when performing date arithmetic / applying date logic.
Hope this helps.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
DaniWeb Marketplace (Sponsored Links)
- Did my computer die? (Troubleshooting Dead Machines)
- Seemingly Simple Issue (MS SQL)
- Struggling with Captcha (PHP)
- Help with dates please (ASP)
- Unable To Right Click Desktop (Viruses, Spyware and other Nasties)
- New to C and needing some guidance (C)
- How to counta repeat records (Visual Basic 4 / 5 / 6)
- Hotmail Login (Windows NT / 2000 / XP / 2003)
- Windows Media Player bitten by virus (Windows 9x / Me)
- My site is not keeping peoples intrests (Website Reviews)
Other Threads in the MS SQL Forum
- Previous Thread: Simple Question PLease URGENT
- Next Thread: Types of JOINS


Linear Mode