











|  |
SLE
Guest
Registered: Not Yet Location: Country: State: Certifications: Working on:
Total Posts: N/A
|
|
DATEPART()
Hi there,
I want to return the date part only of a datetime field without having to
concatenate and cast multiple DATEPART() functions. Is this possible and
how?
Thanks,
--
SLE
Report this post to a moderator
|
|
12-05-02 09:23 AM
|
|
Andrew John
Guest
Registered: Not Yet Location: Country: State: Certifications: Working on:
Total Posts: N/A
|
|
Re: DATEPART()
SLE,
If a cast/convert to string is okay then try:
select cast( current_timestamp as varchar(11))
-- which depending on your date settings and localisation might possibly work
select convert( varchar(10), current_timestamp, 120)
-- Which with the appropriate style, will always work
But if you need it back in a date, then it will take two cast/converts.
select cast( convert( varchar(10), current_timestamp, 120) as datetime )
There are sneakier ways - check the microsoft.public.sqlserver.programming
group archives at google.com, but from memory they are not as clear.
Regards
AJ
"SLE" <infoNOSPAM@proit.be> wrote in message news:3def1896$0$214$ba620e4c@n
ews.skynet.be...
> Hi there,
>
> I want to return the date part only of a datetime field without having to
> concatenate and cast multiple DATEPART() functions. Is this possible and
> how?
>
>
> Thanks,
>
> --
> SLE
>
>
Report this post to a moderator
|
|
12-05-02 10:23 AM
|
|
Martin Lingl
Guest
Registered: Not Yet Location: Country: State: Certifications: Working on:
Total Posts: N/A
|
|
Re: DATEPART()
Hi,
You could CONVERT it to int and back to datetime.
Martin
"Andrew John" <aj@DELETEmistrose.com> wrote in message
news:#su1UHEnCHA.2412@TK2MSFTNGP09...
> SLE,
>
> If a cast/convert to string is okay then try:
>
> select cast( current_timestamp as varchar(11))
> -- which depending on your date settings and localisation might possibly
work
>
> select convert( varchar(10), current_timestamp, 120)
> -- Which with the appropriate style, will always work
>
> But if you need it back in a date, then it will take two cast/converts.
>
> select cast( convert( varchar(10), current_timestamp, 120) as datetime )
>
> There are sneakier ways - check the microsoft.public.sqlserver.programming
> group archives at google.com, but from memory they are not as clear.
>
> Regards
> AJ
>
>
> "SLE" <infoNOSPAM@proit.be> wrote in message
news:3def1896$0$214$ba620e4c@n
ews.skynet.be...
> > Hi there,
> >
> > I want to return the date part only of a datetime field without having
to
> > concatenate and cast multiple DATEPART() functions. Is this possible and
> > how?
> >
> >
> > Thanks,
> >
> > --
> > SLE
> >
> >
>
>
Report this post to a moderator
|
|
12-05-02 11:23 AM
|
|
|
Forum Rules: Who Can Read The Forum? Any registered user or guest.
Who Can Post New Topics? Any registered user.
Who Can Post Replies? Any registered user.
Changes: Messages can be edited by their author.
Posts: HTML code is OFF. Smilies are ON. vB code is ON. [IMG] code is OFF. |
|
ExamNotes forum archive
|