Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 system date

Author  Topic 

smitha
Posting Yak Master

100 Posts

Posted - 2010-01-06 : 06:24:12
how to get the system date in sql

Smitha

Lumbago
Norsk Yak Master

3271 Posts

Posted - 2010-01-06 : 06:25:44
SELECT GETDATE()

- Lumbago
http://xkcd.com/327/
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-06 : 06:29:20
also

SELECT CURRENT_TIMESTAMP
Go to Top of Page

shan
Yak Posting Veteran

84 Posts

Posted - 2010-01-06 : 11:07:53
also
select {fn Now()}
Go to Top of Page

DP978
Constraint Violating Yak Guru

269 Posts

Posted - 2010-01-06 : 11:51:40
I've never seen this last one personally Shan, I noticed that the brackets are required, does that tell SQL it's a system function of some sort? If you don't mind can you just explain this one quickly, I cant find it using the help explorer!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-06 : 11:58:26
quote:
Originally posted by DP978

I've never seen this last one personally Shan, I noticed that the brackets are required, does that tell SQL it's a system function of some sort? If you don't mind can you just explain this one quickly, I cant find it using the help explorer!


its the ODBC canonical function. there are also other functions like

{fn CURRENT_TIMESTAMP()} ,{fn CURRENT_DATE()},{fn CURRENT_TIME()}
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-01-06 : 12:13:42
However - Lumbago's reply is enough for the OP


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-06 : 12:16:15
quote:
Originally posted by webfred

However - Lumbago's reply is enough for the OP


No, you're never too old to Yak'n'Roll if you're too young to die.


But he got quite a bit of handy info
Go to Top of Page

shan
Yak Posting Veteran

84 Posts

Posted - 2010-01-06 : 12:18:49
yes some more ways of doing things
Go to Top of Page

DP978
Constraint Violating Yak Guru

269 Posts

Posted - 2010-01-06 : 12:33:57
Do people use {fn CURRENT_DATE()} instead of the convert(varchar(10),GetDate(), 101) at all? Or is it safer to just use getdate()
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-06 : 12:39:31
quote:
Originally posted by DP978

Do people use {fn CURRENT_DATE()} instead of the convert(varchar(10),GetDate(), 101) at all? Or is it safer to just use getdate()


You can use both. I've not heard of any reasons that forbids you from using canonical funtions.
Go to Top of Page

DP978
Constraint Violating Yak Guru

269 Posts

Posted - 2010-01-06 : 12:53:10
Awesome, thanks for the info. I will most likely remember GetDate() first and foremost, but just in case I use the other I wanted to make sure I was not hurting my query performance.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-01-07 : 01:53:34
quote:
Originally posted by visakh16

quote:
Originally posted by DP978

I've never seen this last one personally Shan, I noticed that the brackets are required, does that tell SQL it's a system function of some sort? If you don't mind can you just explain this one quickly, I cant find it using the help explorer!


its the ODBC canonical function. there are also other functions like

{fn CURRENT_TIMESTAMP()} ,{fn CURRENT_DATE()},{fn CURRENT_TIME()}


Some more

select {fn current_date()}
select {fn current_time()}
select {fn now()}
select {fn extract(hour from getdate())}
select {fn extract(minute from getdate())}
select {fn extract(second from getdate())}
select {fn extract(day from getdate())}
select {fn extract(month from getdate())}
select {fn extract(year from getdate())}
select {fn dayname(GetDate())}
select {fn monthname(GetDate())}
select {fn month(GetDate())}
select {fn year(GetDate())}

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-07 : 01:59:59
quote:
Originally posted by madhivanan

quote:
Originally posted by visakh16

quote:
Originally posted by DP978

I've never seen this last one personally Shan, I noticed that the brackets are required, does that tell SQL it's a system function of some sort? If you don't mind can you just explain this one quickly, I cant find it using the help explorer!


its the ODBC canonical function. there are also other functions like

{fn CURRENT_TIMESTAMP()} ,{fn CURRENT_DATE()},{fn CURRENT_TIME()}


Some more

select {fn current_date()}
select {fn current_time()}
select {fn now()}
select {fn extract(hour from getdate())}
select {fn extract(minute from getdate())}
select {fn extract(second from getdate())}
select {fn extract(day from getdate())}
select {fn extract(month from getdate())}
select {fn extract(year from getdate())}
select {fn dayname(GetDate())}
select {fn monthname(GetDate())}
select {fn month(GetDate())}
select {fn year(GetDate())}

Madhivanan

Failing to plan is Planning to fail


just as a query, have you heard of any points that suggests not to use this? I've not heard any myself.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-01-07 : 02:11:36
quote:
Originally posted by visakh16

quote:
Originally posted by madhivanan

quote:
Originally posted by visakh16

quote:
Originally posted by DP978

I've never seen this last one personally Shan, I noticed that the brackets are required, does that tell SQL it's a system function of some sort? If you don't mind can you just explain this one quickly, I cant find it using the help explorer!


its the ODBC canonical function. there are also other functions like

{fn CURRENT_TIMESTAMP()} ,{fn CURRENT_DATE()},{fn CURRENT_TIME()}


Some more

select {fn current_date()}
select {fn current_time()}
select {fn now()}
select {fn extract(hour from getdate())}
select {fn extract(minute from getdate())}
select {fn extract(second from getdate())}
select {fn extract(day from getdate())}
select {fn extract(month from getdate())}
select {fn extract(year from getdate())}
select {fn dayname(GetDate())}
select {fn monthname(GetDate())}
select {fn month(GetDate())}
select {fn year(GetDate())}

Madhivanan

Failing to plan is Planning to fail


just as a query, have you heard of any points that suggests not to use this? I've not heard any myself.


I dont know. Also there is no proper documentation in BOL

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-07 : 02:20:21
Oh ok. Just checked
Go to Top of Page

balaganapathy.n
Starting Member

18 Posts

Posted - 2010-01-07 : 07:56:00
quote:
Originally posted by shan

also
select {fn Now()}



Thanks, shan, vishak, madhi that was new one to me.

balaganapathy n.

Anything you can imagine is real.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-01-07 : 08:00:14
quote:
Originally posted by balaganapathy.n

quote:
Originally posted by shan

also
select {fn Now()}



Thanks, shan, vishak, madhi that was new one to me.

balaganapathy n.

Anything you can imagine is real.


You are welcome

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -