Month(now()) returns 1 in January. How do I left pad that 1 such that
it will return 01 for all single digit months?
Thanks.If you need an expression in report design, try this:
=IIF(Month(Now())<10,"0" & Month(Now()),"" & Month(Now()))
Or, even simple:
=Right("0" & Month(Now()),2)
"Scott" <SHBOSTON@.gmail.com> wrote in message
news:77e80f94-f3bf-49fc-a8ec-d4c526066713@.v17g2000hsa.googlegroups.com...
> Month(now()) returns 1 in January. How do I left pad that 1 such that
> it will return 01 for all single digit months?
> Thanks.
Showing posts with label digit. Show all posts
Showing posts with label digit. Show all posts
Friday, March 23, 2012
month and 2 digit year
How can I get the month and 2 digit year from a date? For example, how could
I return the month/year like my DESIRED RESULTS 1 & 2 below? Both examples
equal January, 2005? DATEPART seems to only allow 4 digit years.
CODE:
SELECT DATEPART(yy, GETDATE())
Desired Results 1: 05-1
Desired Results 2: 1-051.
SELECT REPLACE(LEFT(CONVERT(char(8), GETDATE(), 2),5),'.','-')
2.
SELECT RIGHT(CONVERT(char(8), GETDATE(), 5),5)
"Scott" wrote:
> How can I get the month and 2 digit year from a date? For example, how cou
ld
> I return the month/year like my DESIRED RESULTS 1 & 2 below? Both examples
> equal January, 2005? DATEPART seems to only allow 4 digit years.
>
> CODE:
> SELECT DATEPART(yy, GETDATE())
> Desired Results 1: 05-1
> Desired Results 2: 1-05
>
>
I return the month/year like my DESIRED RESULTS 1 & 2 below? Both examples
equal January, 2005? DATEPART seems to only allow 4 digit years.
CODE:
SELECT DATEPART(yy, GETDATE())
Desired Results 1: 05-1
Desired Results 2: 1-051.
SELECT REPLACE(LEFT(CONVERT(char(8), GETDATE(), 2),5),'.','-')
2.
SELECT RIGHT(CONVERT(char(8), GETDATE(), 5),5)
"Scott" wrote:
> How can I get the month and 2 digit year from a date? For example, how cou
ld
> I return the month/year like my DESIRED RESULTS 1 & 2 below? Both examples
> equal January, 2005? DATEPART seems to only allow 4 digit years.
>
> CODE:
> SELECT DATEPART(yy, GETDATE())
> Desired Results 1: 05-1
> Desired Results 2: 1-05
>
>
Subscribe to:
Posts (Atom)