Thursday, March 22, 2012

Simple date format question from a new guy

I want to put the date in Year, Month, Day format so todays date,
7/8/2006, will give me 20060708.

The following code code leaves out the zeros for day and month and
gives me 200678

Dim RptDate As String
Dim wkDate As Date
wkDate = Today
RptDate = wkDate.Year & wkDate.Month & wkDate.Day

What is the easiest way to get the format I want?I found the answer:

RptDate = Format(Today, "yyyyMMdd")

I wish they were consistent with making month lower case like year and
day

tom c wrote:

Quote:

Originally Posted by

I want to put the date in Year, Month, Day format so todays date,
7/8/2006, will give me 20060708.
>
The following code code leaves out the zeros for day and month and
gives me 200678
>
Dim RptDate As String
Dim wkDate As Date
wkDate = Today
RptDate = wkDate.Year & wkDate.Month & wkDate.Day
>
What is the easiest way to get the format I want?


Lower case m's are minutes, so there's a trade off there...

+++ Rick --

--

Rick Strahl
West Wind Technologies
http://www.west-wind.com/weblog
http://www.west-wind.com/wwThreads/
"tom c" <tomcarr1@.gmail.comwrote in message
news:1152404665.482449.92280@.75g2000cwc.googlegrou ps.com...

Quote:

Originally Posted by

>I found the answer:
>
RptDate = Format(Today, "yyyyMMdd")
>
I wish they were consistent with making month lower case like year and
day
>
>
>
tom c wrote:

Quote:

Originally Posted by

>I want to put the date in Year, Month, Day format so todays date,
>7/8/2006, will give me 20060708.
>>
>The following code code leaves out the zeros for day and month and
>gives me 200678
>>
> Dim RptDate As String
> Dim wkDate As Date
> wkDate = Today
> RptDate = wkDate.Year & wkDate.Month & wkDate.Day
>>
>What is the easiest way to get the format I want?


>

0 comments:

Post a Comment