Thread: Convert Date
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Andrew Taylor Andrew Taylor is offline
external usenet poster
 
Posts: 225
Default Convert Date

myYear = Format(FirstDate, "YYYY")
mySecondVariable = Format(FirstDate, "YYYY_MM")


StephanieH wrote:
I have a macro that picks up a date in cell and adds a month to it. Now I
need to take the first date it picked up and create two new variables using
that date. The first variable I need is to simply pick out the year from the
first date Ie if FirstDate = 3/1/2006, I need myYear to be "2006". The
second variable I need to set is the FirstDate in YYYY_MM format, ie
"2006_03".

How do you convert the date to these two formats? I've tried
myYear = FirstDate(format, "YYYY") but get "Argument not optional"
and
myYear = FirstDate&format("YYYY") but get "Syntax error"