ExamNotes.net  -  IT certification portal

ForumsCertResearchTop sitesNewslettersFree email
HomeRegister


Exams Notes
Practice exams
Exam games
Questions by email
Online training
Training videos
College degrees
Boot camps
Book store
Links directory
Tell a friend
For webmasters




General discussions > Public newsgroups > microsoft.public.sqlserver.server > DATEPART()

Show a Printable Version
Email This Page to Someone!
Receive updates to this thread



Author DATEPART()
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

Old Post 12-05-02 09:23 AM
Reply w/Quote Edit/Delete Message IP: Logged
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

Old Post 12-05-02 10:23 AM
Reply w/Quote Edit/Delete Message IP: Logged
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

Old Post 12-05-02 11:23 AM
Reply w/Quote Edit/Delete Message IP: Logged
All times are GMT.
Post new thread   Post reply


Forum Jump:
Rate This Thread:
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


Powered by: vBulletin 2.2.8
Copyright ©2000, Jelsoft Enterprises Limited.

  Free Braindumps | mcse braindumps