Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2005
»
SQL Server 2005 Integration Services
»
Convert GETDATE() to YYYYMMDD
21 posts, Page 1 of 3
1
2
3
»
»»
Convert GETDATE() to YYYYMMDD
Rate Topic
Display Mode
Topic Options
Author
Message
rahulsony111
rahulsony111
Posted Monday, December 21, 2009 12:23 PM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Sunday, September 26, 2010 8:29 AM
Points: 113,
Visits: 265
In derived columns i have to convert getdate() to YYYYDDMM.
I dont need time.
I want it in format like 20091221
Please help me
Post #837454
Lynn Pettis
Lynn Pettis
Posted Monday, December 21, 2009 12:29 PM
SSC-Insane
Group: General Forum Members
Last Login: Today @ 7:10 PM
Points: 21,588,
Visits: 27,380
Curious, how many different ways do you plan on asking the same question?
You have asked the same question
here
and
here
just worded it a little different.
May I suggest that you pick one thread and concentrate on that one so that you don't get the same answers and have to answer the same questions multiple times?
Lynn Pettis
For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here
or
when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here
and
here
Managing Transaction Logs
SQL Musings from the Desert
Fountain Valley SQL
(My Mirror Blog)
Post #837459
Lynn Pettis
Lynn Pettis
Posted Monday, December 21, 2009 12:29 PM
SSC-Insane
Group: General Forum Members
Last Login: Today @ 7:10 PM
Points: 21,588,
Visits: 27,380
By the way, I'd store a date as a date, not a numeric value.
Lynn Pettis
For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here
or
when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here
and
here
Managing Transaction Logs
SQL Musings from the Desert
Fountain Valley SQL
(My Mirror Blog)
Post #837460
SQLRNNR
SQLRNNR
Posted Monday, December 21, 2009 12:33 PM
SSCoach
Group: General Forum Members
Last Login: 2 days ago @ 1:46 PM
Points: 18,732,
Visits: 12,329
I'm curious what the need is to convert a date to a Number. I would leave the date as one of the datetime datatype in sql 2005.
Now to get the Date Format you seek, you will need to convert to varchar and check the following:
http://www.sqlusa.com/bestpractices2005/centurydateformat/
Jason
AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server 2008
SQL RNNR
Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #837468
Lynn Pettis
Lynn Pettis
Posted Monday, December 21, 2009 12:35 PM
SSC-Insane
Group: General Forum Members
Last Login: Today @ 7:10 PM
Points: 21,588,
Visits: 27,380
CirquedeSQLeil (12/21/2009)
I'm curious what the need is to convert a date to a Number. I would leave the date as one of the datetime datatype in sql 2005.
Now to get the Date Format you seek, you will need to convert to varchar and check the following:
http://www.sqlusa.com/bestpractices2005/centurydateformat/
Actually, on the SQL side dropping the time portion off getdate is this simple:
dateadd(dd, datediff(dd, 0, getdate()), 0)
Lynn Pettis
For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here
or
when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here
and
here
Managing Transaction Logs
SQL Musings from the Desert
Fountain Valley SQL
(My Mirror Blog)
Post #837469
SQLRNNR
SQLRNNR
Posted Monday, December 21, 2009 12:38 PM
SSCoach
Group: General Forum Members
Last Login: 2 days ago @ 1:46 PM
Points: 18,732,
Visits: 12,329
Lynn Pettis (12/21/2009)
CirquedeSQLeil (12/21/2009)
I'm curious what the need is to convert a date to a Number. I would leave the date as one of the datetime datatype in sql 2005.
Now to get the Date Format you seek, you will need to convert to varchar and check the following:
http://www.sqlusa.com/bestpractices2005/centurydateformat/
Actually, on the SQL side dropping the time portion off getdate is this simple:
dateadd(dd, datediff(dd, 0, getdate()), 0)
Noted and added to my toolbox - I had never used that method. Thanks Lynn.
Jason
AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server 2008
SQL RNNR
Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #837476
Lynn Pettis
Lynn Pettis
Posted Monday, December 21, 2009 12:40 PM
SSC-Insane
Group: General Forum Members
Last Login: Today @ 7:10 PM
Points: 21,588,
Visits: 27,380
CirquedeSQLeil (12/21/2009)
Lynn Pettis (12/21/2009)
CirquedeSQLeil (12/21/2009)
I'm curious what the need is to convert a date to a Number. I would leave the date as one of the datetime datatype in sql 2005.
Now to get the Date Format you seek, you will need to convert to varchar and check the following:
http://www.sqlusa.com/bestpractices2005/centurydateformat/
Actually, on the SQL side dropping the time portion off getdate is this simple:
dateadd(dd, datediff(dd, 0, getdate()), 0)
Noted and added to my toolbox - I had never used that method. Thanks Lynn.
Check my blog for some other date routines. They might come in handy as well.
Lynn Pettis
For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here
or
when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here
and
here
Managing Transaction Logs
SQL Musings from the Desert
Fountain Valley SQL
(My Mirror Blog)
Post #837479
SQLRNNR
SQLRNNR
Posted Monday, December 21, 2009 12:41 PM
SSCoach
Group: General Forum Members
Last Login: 2 days ago @ 1:46 PM
Points: 18,732,
Visits: 12,329
Thanks - will do.
Jason
AKA CirqueDeSQLeil
I have given a name to my pain...
MCM SQL Server 2008
SQL RNNR
Posting Performance Based Questions - Gail Shaw
Posting Data Etiquette - Jeff Moden
Hidden RBAR - Jeff Moden
VLFs and the Tran Log - Kimberly Tripp
Post #837480
rahulsony111
rahulsony111
Posted Monday, December 21, 2009 12:46 PM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Sunday, September 26, 2010 8:29 AM
Points: 113,
Visits: 265
I am trying this from 5 hrs and unable to get a solution.
In target table i have that column as numeric.
I tried getdate() with datatype databasedate but it is returning 2009-12-21. So that value is not going into target table sand saying it as invalid number.
I want it ti look like 20091221, only then it goes into targat table
Post #837486
Lynn Pettis
Lynn Pettis
Posted Monday, December 21, 2009 12:51 PM
SSC-Insane
Group: General Forum Members
Last Login: Today @ 7:10 PM
Points: 21,588,
Visits: 27,380
rahulsony111 (12/21/2009)
I am trying this from 5 hrs and unable to get a solution.
In target table i have that column as numeric.
I tried getdate() with datatype databasedate but it is returning 2009-12-21. So that value is not going into target table sand saying it as invalid number.
I want it ti look like 20091221, only then it goes into targat table
As mentioned in one of the other threads where you asked the "same" question, and since you seem fixed on storing the date as an integer, in SQL:
cast(convert(varchar(8), getdate(), 112) as int)
Lynn Pettis
For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here
or
when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here
and
here
Managing Transaction Logs
SQL Musings from the Desert
Fountain Valley SQL
(My Mirror Blog)
Post #837490
« Prev Topic
|
Next Topic »
21 posts, Page 1 of 3
1
2
3
»
»»
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.