SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 How to get date in t-sql
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

AskSQLTeam
Ask SQLTeam Question

USA
0 Posts

Posted - 04/25/2001 :  08:56:36  Show Profile  Visit AskSQLTeam's Homepage  Reply with Quote
Mike writes "Hi! What is the best way to get
date(yyyy,mm,dd) using t-sql against
sql 2000?

Datepart() returns only a year OR a month OR a day.
Am I missing smth?

Thanks"

Merkin
Funky Drop Bear Fearing SQL Dude!

Australia
4970 Posts

Posted - 04/25/2001 :  09:00:43  Show Profile  Visit Merkin's Homepage  Reply with Quote
Hi

GetDate() will get the current date.

To format it, use either the convert function or build a string using datepart.



Damian
Go to Top of Page

shane
Starting Member

USA
33 Posts

Posted - 04/25/2001 :  09:08:21  Show Profile  Reply with Quote
You could do it a couple different ways:

1. convert(varchar,getdate(),102)
There are several different date formats you can use with the convert function.

2. convert(varchar,datepart(yy,getdate())) + ' ' + convert(varchar,datepart(mm,getdate())) + ' ' + convert(varchar,datepart(dd,getdate()))
Or you parse up the dates manually if you need a proprietary format.




Go to Top of Page

robvolk
Most Valuable Yak

USA
15658 Posts

Posted - 04/25/2001 :  09:57:08  Show Profile  Visit robvolk's Homepage  Reply with Quote
Another interpretation of the question, "How to get a date in T-SQL?":

Find out what your database's interests are, and talk animatedly about them.

Use subtle flattery, "Wow, that's a really nice stored procedure you got there."

Don't overemphasize or show too much interest in physical hardware and specs, most databases consider that shallow and sexist.

Remember that each database is unique, what works well for one may be a total disaster for another.

Always listen. CPU utilization might only be 7%, but that might be a problem for some databases. Be empathetic.

Don't assume that because everything goes well at first that you'll be granted full permissions to every part of the database. Work your way up to it, and enjoy the journey. Your database will appreciate the attention.

...and always remember, GetDate() will get you a date, but it may not turn out exactly the way you want it.

SELECT ThePerfectWoman
FROM AllTheWomenInTheWorld
WHERE HerInterests Like Mine
AND CurrentMate Is Null
AND CurrentlyLives IN ('Yonkers', 'Bondi Beach', 'São Paulo')
GROUP BY CASE WHEN AsManyAsWillHaveMe>AsManyAsMyStaminaWillAllow
THEN AsManyAsWillHaveMe ELSE AsManyAsMyStaminaWillAllow * 2 END
HAVING Max(Libido)>=Mine


I really need to find better things to do with my time

Edited by - robvolk on 04/25/2001 19:38:08
Go to Top of Page

OwnedByTheMan
Starting Member

Canada
35 Posts

Posted - 04/25/2001 :  10:44:11  Show Profile  Reply with Quote
...and don't forget to mention the size of your log.

Go to Top of Page

Stevo
Starting Member

USA
8 Posts

Posted - 04/25/2001 :  21:16:15  Show Profile  Visit Stevo's Homepage  Send Stevo an AOL message  Send Stevo a Yahoo! Message  Reply with Quote
Be careful about the size of your log actually. I had a server that was offended at my memory space-filling transaction log. After truncating several and backing up others[logs] I realized I needed to simply delete multiple 1 gig+ files on the server. SQL likes it's space, always respect that.

+Stevo
Go to Top of Page

nr
SQLTeam MVY

United Kingdom
12543 Posts

Posted - 04/25/2001 :  22:18:04  Show Profile  Visit nr's Homepage  Reply with Quote
Don't overemphasize or show too much interest in physical hardware and specs.

Trying to impress a database with too much hardware is either a sign of lack of relational experience (other people) or intelligent planning for future little databases (me).

Go to Top of Page

rrb
SQLTeam Poet Laureate

Australia
1479 Posts

Posted - 08/07/2002 :  22:55:47  Show Profile  Reply with Quote
quote:

Be careful about the size of your log actually. I had a server that was offended at my memory space-filling transaction log. After truncating several and backing up others[logs] I realized I needed to simply delete multiple 1 gig+ files on the server. SQL likes it's space, always respect that.


Truncating your log? <OUCH>

I'll go for the file deletion option EVERY time

(Aw come on! Someone had to say it!)

Guess I should also add (at this point) that probably not a bad idea to wait a while before the creation of little databases too.

--
I hope that when I die someone will say of me "That guy sure owed me a lot of money"

Edited by - rrb on 08/07/2002 22:59:20
Go to Top of Page

Tim
Starting Member

Australia
392 Posts

Posted - 09/22/2002 :  23:16:43  Show Profile  Reply with Quote
Which database will be give the best result for getdate() ?

a. SINGLE_USER
b. MULTI_USER
c. RESTRICTED_USER


----
Nancy Davolio: Best looking chick at Northwind 1992-2000
Go to Top of Page

xr280xr
Starting Member

2 Posts

Posted - 07/12/2011 :  11:28:25  Show Profile  Reply with Quote
robvolk, hilarious.
Go to Top of Page

Seventhnight
Flowing Fount of Yak Knowledge

USA
2878 Posts

Posted - 07/12/2011 :  13:16:37  Show Profile  Visit Seventhnight's Homepage  Reply with Quote
Never saw this... but I like it

Corey

I Has Returned!!
Go to Top of Page

3magic
Starting Member

United Arab Emirates
14 Posts

Posted - 08/04/2011 :  02:45:14  Show Profile  Reply with Quote
Write Shane, I agreed by your answer. My ans is also this.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000