Link to home
Start Free TrialLog in
Avatar of HKFuey
HKFueyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

VBA Date syntax

VBA Syntax

I have this line: Format(Date, "YYWW") but in January (e.g. 31/01/2019) this returns '195' week 5 is a single digit.

For single number weeks I need it to be in 2 digits so wee 5 would be '05'

Anyone know how?
Avatar of Alan
Alan
Flag of New Zealand image

I can't test right now but maybe:

Format(Date, "YY")  & Format(Date, "WW")


Alan.
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Norie
Norie

Try this.
Format(Date, "YY") & Format(DatePart("WW", Date), "00")

Open in new window

Avatar of HKFuey

ASKER

Hi Alan, that gives me single digit weeks early in the year.

Hi Ryan, that worked with minor adjustment: -
YrWk = Format(Date, "YY") & Right("0" & Format(Date, "WW"), 2)
Avatar of HKFuey

ASKER

Hi Norrie, I think we 'cross posted'. Thank you for your input.