May 9, 2012 at 8:25 am
Hi,
How can I get the m/d/yy format instead of m/d/yyyy
rightnow my query looks like below:
select convert(varchar(2), month(getdate())) + '/'
+ convert(varchar(2), day(getdate())) + '/'
+ convert(varchar(4), year(getdate()))
then,
I tried below but I get * as year when I run it
select convert(varchar(2), month(getdate())) + '/'
+ convert(varchar(2), day(getdate())) + '/'
+ convert(varchar(2), year(getdate())) end
thanks !!
May 9, 2012 at 8:31 am
select convert(varchar(2), month(getdate())) + '/'
+ convert(varchar(2), day(getdate())) + '/'
+ RIGHT(convert(varchar(4), year(getdate())),2)
May 9, 2012 at 8:34 am
This:
select convert(varchar(2), month(getdate())) + '/' + convert(varchar(2), day(getdate())) + '/' + RIGHT(DATENAME(yy,GETDATE()),2);
May 9, 2012 at 8:44 am
The BEST way to get date formatting is in the front end. ๐
If you must use sql than use Lynn's approach.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 โ Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
May 9, 2012 at 10:07 am
Thanks all for your replies !!
May 9, 2012 at 11:29 pm
BWAAA-HAAA!!! This will do it! :-P:-D Makes a "great" interview question. :sick:
WITH F(x) AS (SELECT TOP (CHECKSUM(66-ASCII('A'))) '/'+CONVERT(CHAR(8),GETDATE(),CAST(EXP(0) AS INT)) FROM sys.objects)
SELECT STUFF(REPLACE(LEFT(x,POWER(73,1/2)*POWER(25,1/2.0)),'/0','/')
+ RIGHT(x,LOG10(10000)),CONVERT(INT,SIN(PI()/2)),0x47-70,SUBSTRING('xxx',-5,1))
FROM F;
--Jeff Moden
Change is inevitable... Change for the better is not.
May 9, 2012 at 11:33 pm
Jeff Moden (5/9/2012)
BWAAA-HAAA!!! This will do it! :-P:-D Makes a "great" interview question. :sick:
WITH F(x) AS (SELECT TOP (CHECKSUM(66-ASCII('A'))) '/'+CONVERT(CHAR(8),GETDATE(),CAST(EXP(0) AS INT)) FROM sys.objects)
SELECT STUFF(REPLACE(LEFT(x,POWER(73,1/2)*POWER(25,1/2.0)),'/0','/')
+ RIGHT(x,LOG10(10000)),CONVERT(INT,SIN(PI()/2)),0x47-70,SUBSTRING('xxx',-5,1))
FROM F;
Even though I think you're showing off, I have to ask.
Can I use this? :w00t:
My thought question: Have you ever been told that your query runs too fast?
My advice:
INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.
Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
Since random numbers are too important to be left to chance, let's generate some![/url]
Learn to understand recursive CTEs by example.[/url]
[url url=http://www.sqlservercentral.com/articles/St
May 10, 2012 at 12:16 am
dwain.c (5/9/2012)
Even though I think you're showing off, I have to ask.Can I use this? :w00t:
Sure thing. The only price you have to pay is to tell me for what. ๐ I smell a good prank coming up.
--Jeff Moden
Change is inevitable... Change for the better is not.
May 10, 2012 at 1:42 am
Jeff Moden (5/9/2012)
BWAAA-HAAA!!! This will do it! :-P:-D Makes a "great" interview question. :sick:
WITH F(x) AS (SELECT TOP (CHECKSUM(66-ASCII('A'))) '/'+CONVERT(CHAR(8),GETDATE(),CAST(EXP(0) AS INT)) FROM sys.objects)
SELECT STUFF(REPLACE(LEFT(x,POWER(73,1/2)*POWER(25,1/2.0)),'/0','/')
+ RIGHT(x,LOG10(10000)),CONVERT(INT,SIN(PI()/2)),0x47-70,SUBSTRING('xxx',-5,1))
FROM F;
ROTFLOL! Whoever wrote this had way too much time on their hands!
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
May 10, 2012 at 1:47 am
SELECT STUFF(REPLACE('/'+CONVERT(VARCHAR(10),GETDATE(),1),'/0','/'),1,1,'')
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
May 10, 2012 at 2:18 am
if its a date time column could you not just do
select CONVERT(varchar,getdate(),10)
May 10, 2012 at 2:20 am
anthony.green (5/10/2012)
if its a date time column could you not just do
select CONVERT(varchar,getdate(),10)
No leading zero for days and months...
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
May 10, 2012 at 6:58 am
ChrisM@Work (5/10/2012)
SELECT STUFF(REPLACE('/'+CONVERT(VARCHAR(10),GETDATE(),1),'/0','/'),1,1,'')
That's what my original code looked like. The problem is that it knocks out the leading 0 on 2 digit years when they happen. Now, if the wanted 4 digit years, then that's the way to go! ๐
--Jeff Moden
Change is inevitable... Change for the better is not.
May 10, 2012 at 9:43 am
thanks all
Viewing 14 posts - 1 through 14 (of 14 total)
You must be logged in to reply to this topic. Login to reply