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] >-----Original Message-----
>>For eg. if the month is January, in the query
>>it returns 1, I want it to return 01.
>Ex:
>select right('0' + cast(datepart(mm,workorderdate)as
varchar(2)),2) 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?
>
>--use convert function to do that
>Ex:
>select convert(varchar(8), Workorderdate, 112) from table
>
>- Vishal
>"Alice" <gth@hotmail.com> wrote in message
>news:568b01c37c94$5efb2ff0$a601280a@phx.gbl...
>> 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!
>> -Al
>
>
>.
[quoted text, click to view] >For eg. if the month is January, in the query
>it returns 1, I want it to return 01.
Ex:
select right('0' + cast(datepart(mm,workorderdate)as varchar(2)),2) from
<tablename>
[quoted text, click to view] >It would be still better if I could get the entire
>date in yyyymmdd format from Workorderdate. Is there
>a function to do that?
--use convert function to do that
Ex:
select convert(varchar(8), Workorderdate, 112) from table
- Vishal
[quoted text, click to view] "Alice" <gth@hotmail.com> wrote in message
news:568b01c37c94$5efb2ff0$a601280a@phx.gbl...
> 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!
> -Al
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] "Alice" <gth@hotmail.com> wrote in message
news:060a01c37ca6$3be71080$a301280a@phx.gbl...
> 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
>
> >-----Original Message-----
> >>For eg. if the month is January, in the query
> >>it returns 1, I want it to return 01.
> >Ex:
> >select right('0' + cast(datepart(mm,workorderdate)as
> varchar(2)),2) 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?
> >
> >--use convert function to do that
> >Ex:
> >select convert(varchar(8), Workorderdate, 112) from table
> >
> >- Vishal
> >"Alice" <gth@hotmail.com> wrote in message
> >news:568b01c37c94$5efb2ff0$a601280a@phx.gbl...
> >> 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!
> >> -Al
> >
> >
> >.
> >