Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default Convert Date

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"
  #2   Report Post  
Posted to microsoft.public.excel.programming
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"


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default Convert Date

Yay. It works perfectly.

Thanks for your help Ardus.



"Ardus Petus" wrote:

'----------------------------------------------------
Dim myYear as string
dim MyYearMonth as string

myYear = format(FirstDate,"yyyy")
myYearMonth =f ormat(FirstDate,"yyyy_mm")
'----------------------------------------------------

HTH
--
AP

"StephanieH" a écrit dans le message
de news: ...
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"




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I convert US date with 12hr format to European date 24hr Enda K Excel Discussion (Misc queries) 1 November 15th 09 09:59 AM
Is it possible to convert solar date to lunar date using excel? GOH Excel Discussion (Misc queries) 1 October 25th 09 09:21 AM
How to convert Gregorian date into Hijri Date in Excel 2007? Ahmed Excel Discussion (Misc queries) 2 February 6th 09 03:59 PM
Convert a julian gregorian date code into a regular date Robert Excel Worksheet Functions 3 June 13th 06 07:03 PM
Convert date to length of time in months from set date MJUK Excel Worksheet Functions 1 March 19th 05 06:31 PM


All times are GMT +1. The time now is 06:19 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"