• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 61
  • Last Modified:

How would i use date part to get todays date as YYMM

How would i use date part to get todays date as YYMM.

Datepart does not seem to like "MM"
  • 2
1 Solution
Bill PrewCommented:
Using datepart you can do:

strYYMM = Right(DatePart("yyyy", Now), 2) & Right("0" & DatePart("m", Now), 2)

or use the build in Year() and Month() functions.

strYYMM = Right(Year(Now), 2) & Right("0" & Month(Now), 2)

Notice these return an integer, so for month we want to left pad with a "0" to make sure we always get two digits for months less than 10.

vbnetcoderAuthor Commented:
Bill PrewCommented:
Glad that helped.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now