Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing a date function

Status
Not open for further replies.

newtosql

Programmer
Joined
Apr 7, 2003
Messages
18
Location
US
Hi,

I think I need to write a function to avoid using this query over and over again.

CAST(DATEPART(YEAR,getdate()) AS VARCHAR) +
REPLICATE('0',2-LEN(CAST(DATEPART(MONTH,getdate()) AS VARCHAR))) +
CAST(DATEPART(MONTH,getdate()) AS VARCHAR) +
REPLICATE('0',2-LEN(CAST(DATEPART(DAY,getdate()) AS VARCHAR))) +
CAST(DATEPART(DAY,getdate()) AS VARCHAR)

Any ideas?
 
try this

select convert (varchar,getdate(),112)

BOL says its yymmdd but it is actually yyyymmdd

Matt

Brighton, UK
 
Hi newtosql,

there is an in-built function you can use as :
--------
select convert(varchar,getdate(),112)
--------

this will give you the same result as of your query.

If it is not what you wanted, then do post your reply.


Raj
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top