Groups | Blog | Home
all groups > sql server mseq > september 2003 >

sql server mseq : Left Pad month


Alice
9/16/2003 1:51:58 PM
I have a need to left pad the month with 0, can you
help me do this?

For eg. if the month is January, in the query
it returns 1, I want it to return 01.

select datepart(mm,Workorderdate) from <tablename>

It would be still better if I could get the entire
date in yyyymmdd format from Workorderdate. Is there
a function to do that?

Thank you for your help!
Alice
9/16/2003 3:59:50 PM
Hi Vishal,

It works, thank you very much!

Tell me in the 2nd convert statement -
select convert(varchar(8), Workorderdate, 112) from table

why did you use 112?

If I wanted the date format to be different from
yyyymmmdd, say if I want the date format to be ddmmyyyy,
then how do I convert it?

Thanks again for your time.
-Alice

[quoted text, click to view]
Vishal Parkar
9/16/2003 4:10:30 PM
[quoted text, click to view]
Ex:
select right('0' + cast(datepart(mm,workorderdate)as varchar(2)),2) from
<tablename>


[quoted text, click to view]

--use convert function to do that
Ex:
select convert(varchar(8), Workorderdate, 112) from table

- Vishal
[quoted text, click to view]

Anith Sen
9/16/2003 4:13:36 PM
Please refer to the response to the post titled "leading 0" from awwin
(9/12/2003).

--
- Anith
( Please reply to newsgroups only )

Vishal Parkar
9/16/2003 5:12:34 PM
There is no format for ddmmyyyy you will have to do something as follows.

select replace(convert(varchar(20), getdate(), 104), '.','') today

- Vishal

[quoted text, click to view]

AddThis Social Bookmark Button