SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


select from GETDATE()?


select from GETDATE()?

Author
Message
obarahmeh
obarahmeh
Say Hey Kid
Say Hey Kid (675 reputation)Say Hey Kid (675 reputation)Say Hey Kid (675 reputation)Say Hey Kid (675 reputation)Say Hey Kid (675 reputation)Say Hey Kid (675 reputation)Say Hey Kid (675 reputation)Say Hey Kid (675 reputation)

Group: General Forum Members
Points: 675 Visits: 309
Dear All,
When you run the following command:
SELECT GETDATE() AS [CurrentDateTime]
The Result is : 2008-09-24 12:47:11.587

The question is: How can I get the following result from the above query:
20080924
ChrisM@Work
ChrisM@Work
SSC Guru
SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)

Group: General Forum Members
Points: 73208 Visits: 20316
SELECT REPLACE(CONVERT(VARCHAR(10), GETDATE(), 102), '.', '')



“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
Madhivanan-208264
Madhivanan-208264
Hall of Fame
Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)

Group: General Forum Members
Points: 3089 Visits: 476
obarahmeh (9/24/2008)
Dear All,
When you run the following command:
SELECT GETDATE() AS [CurrentDateTime]
The Result is : 2008-09-24 12:47:11.587

The question is: How can I get the following result from the above query:
20080924

Where do you want to show/use formatted dates?

If it is only for display

SELECT convert(varchar(8),getdate(),112)





Madhivanan

Failing to plan is Planning to fail
Madhivanan-208264
Madhivanan-208264
Hall of Fame
Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)

Group: General Forum Members
Points: 3089 Visits: 476
Chris Morris (9/24/2008)
SELECT REPLACE(CONVERT(VARCHAR(10), GETDATE(), 102), '.', '')


You dont need additional replace function
See my first reply Smile



Madhivanan

Failing to plan is Planning to fail
obarahmeh
obarahmeh
Say Hey Kid
Say Hey Kid (675 reputation)Say Hey Kid (675 reputation)Say Hey Kid (675 reputation)Say Hey Kid (675 reputation)Say Hey Kid (675 reputation)Say Hey Kid (675 reputation)Say Hey Kid (675 reputation)Say Hey Kid (675 reputation)

Group: General Forum Members
Points: 675 Visits: 309
Thank you very much...Both of you correct.
Thanks again
Madhivanan-208264
Madhivanan-208264
Hall of Fame
Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)

Group: General Forum Members
Points: 3089 Visits: 476
obarahmeh (9/24/2008)
Thank you very much...Both of you correct.
Thanks again

Well. You didnt answer to my question Wink



Madhivanan

Failing to plan is Planning to fail
ChrisM@Work
ChrisM@Work
SSC Guru
SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)SSC Guru (73K reputation)

Group: General Forum Members
Points: 73208 Visits: 20316
Madhivanan, quite right! I don't know why the conversion I posted is being used - possibly from a previous version. It's used extensively here to generate a suffix for export filenames.

Thanks

ChrisM

“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
obarahmeh
obarahmeh
Say Hey Kid
Say Hey Kid (675 reputation)Say Hey Kid (675 reputation)Say Hey Kid (675 reputation)Say Hey Kid (675 reputation)Say Hey Kid (675 reputation)Say Hey Kid (675 reputation)Say Hey Kid (675 reputation)Say Hey Kid (675 reputation)

Group: General Forum Members
Points: 675 Visits: 309
well, I have a trigger that reads the latest inserted data and insert them into another table. I've wrote the trigger, then it inserted all data from the first table, where I need only the daily data inserted. and so, I've added a condition where date = today date.
and I am checking that now.
Madhivanan-208264
Madhivanan-208264
Hall of Fame
Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)Hall of Fame (3.1K reputation)

Group: General Forum Members
Points: 3089 Visits: 476
obarahmeh (9/24/2008)
well, I have a trigger that reads the latest inserted data and insert them into another table. I've wrote the trigger, then it inserted all data from the first table, where I need only the daily data inserted. and so, I've added a condition where date = today date.
and I am checking that now.

If you want to find out today's data, use

where datecol>=dateadd(day,datediff(day,0,getdate()),0) and
datecol<dateadd(day,datediff(day,0,getdate()),1)





Madhivanan

Failing to plan is Planning to fail
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum







































































































































































SQLServerCentral


Search