Home All Groups Group Topic Archive Search About

Date part only without using Convert(char.....)

Author
1 Jul 2005 11:44 AM
NH
select convert(char,getdate(),101) will return the date without the time part.

Is there a way doing the same without converting it to a char? I need the
date part only but it must be a datetime data type.

Author
1 Jul 2005 11:52 AM
Jens Süßmeyer
Why do you need a datetime type ?
There is no Date Type in SQL Server, so you can´t convert itin something
like theformat 01-01-05 unless you convert it to char / varchar.

If you want to do something in your frontend with that data you should
consider letting your frontend do this.


HTH, Jens SUessmeyer.

---
http://www.sqlserver2005.de
---

Show quote
"NH" <N*@discussions.microsoft.com> schrieb im Newsbeitrag
news:60628838-6E00-4778-833C-A0FC0AFB1124@microsoft.com...
> select convert(char,getdate(),101) will return the date without the time
> part.
>
> Is there a way doing the same without converting it to a char? I need the
> date part only but it must be a datetime data type.
Author
1 Jul 2005 11:59 AM
NH
Its for SQL Reporting services, it needs a datetime parameter, if you
convert\cast it into a date only part it doesnt work. I'd rather display the
date paramter as "2005-10-20" rather than "2005-10-20 00:00:00"

Show quote
"Jens Süßmeyer" wrote:

> Why do you need a datetime type ?
> There is no Date Type in SQL Server, so you can´t convert itin something
> like theformat 01-01-05 unless you convert it to char / varchar.
>
> If you want to do something in your frontend with that data you should
> consider letting your frontend do this.
>
>
> HTH, Jens SUessmeyer.
>
> ---
> http://www.sqlserver2005.de
> ---
>
> "NH" <N*@discussions.microsoft.com> schrieb im Newsbeitrag
> news:60628838-6E00-4778-833C-A0FC0AFB1124@microsoft.com...
> > select convert(char,getdate(),101) will return the date without the time
> > part.
> >
> > Is there a way doing the same without converting it to a char? I need the
> > date part only but it must be a datetime data type.
>
>
>
Author
2 Jul 2005 3:22 PM
--CELKO--
1)  The basic principle of a tiered architecture is that display is
done in the frpon, not the data base.  You are still writing code as
SQL were a Cobol file system, integrated worth with the applications.

2) Time comes in duration, so you need to code the entire date
'2005-10-20' as a pair of srart and stop times in your schema. :
(''2005-10-20 00:00:00', ''2005-10-20 23:59:59.999999..)  with the
appropiate constraints.  This will let you use BETWEEN predicates for
queries.

3) SQL Server has a DATETIME data type; there is no DATE data type.  If
you want an ugly proprietary way to get midnight try this:

CAST (FLOOR (CAST (@my_date AS FLOAT)) AS DATETIME) AS start_date;

You can then get the open end of the interval with a CEILING() function
and a DATEDIFF to clip off a fraction of a second.
Author
5 Jul 2005 3:42 PM
Ross Presser
On Fri, 1 Jul 2005 04:59:23 -0700, NH wrote:

> Its for SQL Reporting services, it needs a datetime parameter, if you
> convert\cast it into a date only part it doesnt work.

a datetime ALWAYS represents an instant in time, not a whole day.

If you need a datetime value for Reporting Services, you're not going to
get anything else. 

If Reporting Services is demanding a datetime value, you must give it a
datetime value.

> I'd rather display the
> date paramter as "2005-10-20" rather than "2005-10-20 00:00:00"

If Reporting Services is not printing what you want, then perhaps you'd
better ask in a Reporting Services group.  Here we are but SQL programmers.
Author
1 Jul 2005 11:55 AM
Tom Moreau
Then you can cast or convert it further:

select
    cast (convert(char,getdate(),101)  as datetime)
,   convert (datetime, convert(char,getdate(),101))

--
   Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON   Canada
www.pinpub.com
..
"NH" <N*@discussions.microsoft.com> wrote in message
news:60628838-6E00-4778-833C-A0FC0AFB1124@microsoft.com...
select convert(char,getdate(),101) will return the date without the time
part.

Is there a way doing the same without converting it to a char? I need the
date part only but it must be a datetime data type.
Author
1 Jul 2005 1:11 PM
NH
But that still returns the date as "2005-10-20 00:00:00"....

Show quote
"Tom Moreau" wrote:

> Then you can cast or convert it further:
>
> select
>     cast (convert(char,getdate(),101)  as datetime)
> ,   convert (datetime, convert(char,getdate(),101))
>
> --
>    Tom
>
> ----------------------------------------------------
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON   Canada
> www.pinpub.com
> ..
> "NH" <N*@discussions.microsoft.com> wrote in message
> news:60628838-6E00-4778-833C-A0FC0AFB1124@microsoft.com...
> select convert(char,getdate(),101) will return the date without the time
> part.
>
> Is there a way doing the same without converting it to a char? I need the
> date part only but it must be a datetime data type.
>
>
Author
1 Jul 2005 2:32 PM
Foo Man Chew
> But that still returns the date as "2005-10-20 0:00:00"....

Then use CONVERT!  There is no such thing as a date only.  For the third
time.
Author
1 Jul 2005 2:40 PM
NH
If you read the previous reply you'll see that it suggested you could do what
I want. So its not like I am dumb and cant undestand a replies. So why dont
you just go away if you are not going to be helpful

Show quote
"Foo Man Chew" wrote:

> > But that still returns the date as "2005-10-20 0:00:00"....
>
> Then use CONVERT!  There is no such thing as a date only.  For the third
> time.
>
>
>
Author
1 Jul 2005 4:00 PM
Foo Man Chew
> If you read the previous reply you'll see that it suggested you could do
> what
> I want. So its not like I am dumb and cant undestand a replies. So why
> dont
> you just go away if you are not going to be helpful

I'll go away.  Just keep in mind that I was trying to help you "get it"
because you don't seem to.  Have fun.
Author
1 Jul 2005 3:08 PM
Tom Moreau
Can't you format it in RS?

--
   Tom

----------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON   Canada
www.pinpub.com
..
"NH" <N*@discussions.microsoft.com> wrote in message
news:2D176084-6E45-49DB-A243-43CE2F53C819@microsoft.com...
But that still returns the date as "2005-10-20 00:00:00"....

Show quote
"Tom Moreau" wrote:

> Then you can cast or convert it further:
>
> select
>     cast (convert(char,getdate(),101)  as datetime)
> ,   convert (datetime, convert(char,getdate(),101))
>
> --
>    Tom
>
> ----------------------------------------------------
> Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
> SQL Server MVP
> Columnist, SQL Server Professional
> Toronto, ON   Canada
> www.pinpub.com
> ..
> "NH" <N*@discussions.microsoft.com> wrote in message
> news:60628838-6E00-4778-833C-A0FC0AFB1124@microsoft.com...
> select convert(char,getdate(),101) will return the date without the time
> part.
>
> Is there a way doing the same without converting it to a char? I need the
> date part only but it must be a datetime data type.
>
>

AddThis Social Bookmark Button