Unix Technical Forum

Simple SQL Query (To Neglect time from DateTime DataType)

This is a discussion on Simple SQL Query (To Neglect time from DateTime DataType) within the SQL Server forums, part of the Microsoft SQL Server category; --> we have a table like this OrderNo OrderDate 1 2005-11-04 01:12:47.000 2 2005-11-19 04:26:54.000 3 2005-11-16 11:03:23.000 4 2005-11-21 ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-29-2008, 02:57 PM
kashifsulemani@hotmail.com
 
Posts: n/a
Default Simple SQL Query (To Neglect time from DateTime DataType)


we have a table like this

OrderNo OrderDate
1 2005-11-04 01:12:47.000
2 2005-11-19 04:26:54.000
3 2005-11-16 11:03:23.000
4 2005-11-21 15:58:37.000
5 2005-11-24 21:45:04.000


what will be the sql query, so that the Result look like this.
only to neqlect the time factor from datetime data type .


OrderNo OrderDate
1 2005-11-04
2 2005-11-19
3 2005-11-16
4 2005-11-21
5 2005-11-24

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-29-2008, 02:57 PM
helmut woess
 
Posts: n/a
Default Re: Simple SQL Query (To Neglect time from DateTime DataType)

Am 17 Nov 2005 12:34:35 -0800 schrieb kashifsulemani@hotmail.com:

> we have a table like this
>
> OrderNo OrderDate
> 1 2005-11-04 01:12:47.000
> 2 2005-11-19 04:26:54.000
> 3 2005-11-16 11:03:23.000
> 4 2005-11-21 15:58:37.000
> 5 2005-11-24 21:45:04.000
>
>
> what will be the sql query, so that the Result look like this.
> only to neqlect the time factor from datetime data type .
>
>
> OrderNo OrderDate
> 1 2005-11-04
> 2 2005-11-19
> 3 2005-11-16
> 4 2005-11-21
> 5 2005-11-24


select orderno, convert(char(10),orderdate,120)

bye,
Helmut
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-29-2008, 02:57 PM
ZeldorBlat
 
Posts: n/a
Default Re: Simple SQL Query (To Neglect time from DateTime DataType)

If you wanto remove the time portion and keep the value as datetime
(instead of char) you can use this:

CAST(FLOOR(CAST(someDate AS float)) AS datetime)

I always thought that was a nifty idiom -- but I'm not sure of the
performance implications (if any).

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-29-2008, 02:57 PM
Hugo Kornelis
 
Posts: n/a
Default Re: Simple SQL Query (To Neglect time from DateTime DataType)

On 17 Nov 2005 14:52:41 -0800, ZeldorBlat wrote:

>If you wanto remove the time portion and keep the value as datetime
>(instead of char) you can use this:
>
>CAST(FLOOR(CAST(someDate AS float)) AS datetime)
>
>I always thought that was a nifty idiom -- but I'm not sure of the
>performance implications (if any).


Hi ZeldorBlat,

This works, but it relies on the (undocumented, as far as I know)
conversion rules for datetime to float and float to datetime. Relying on
undocumented behaviour is allways dangerous.

Here's a safer way to trim the time from a date while still getting a
datetime result:

DATEADD(day, DATEDIFF(day, '20000101', someDate), '20000101')

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-29-2008, 02:57 PM
ZeldorBlat
 
Posts: n/a
Default Re: Simple SQL Query (To Neglect time from DateTime DataType)

>Here's a safer way to trim the time from a date while still getting a
>datetime result:
>
>DATEADD(day, DATEDIFF(day, '20000101', someDate), '20000101')


Point taken. I like that one, too.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 02:18 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com