Training, Consulting and PMO Augmentation

We Prevent Crunch and Project Crashes!

Functions to manipulate Date and time in MS Project VBA

| 1 Comment

In today’s write out, we will explore few of the functions available in MS Project to manipulate Date and Time data in MS Project.

Msgbox DatePart(“yyyy”, “15/10/1998″)                     ‘returns 1998

—-
Msgbox DateDiff(“d”, “04/01/2012″, “04/05/2012″)               ‘ returns 4

—–

Msgbox DateSerial(2004, 6, 30)                              ’ returns 6/30/2004

—-

DateAdd ( interval, number, date )

where interval can be: yyyy for Year, q for Quarter, m for Month, y  for Day of the year, d for Day, w for Weekday, ww for Week, h for Hour, n for Minute, s for Second

Msgbox  DateAdd(“q”, 2, “22/11/2003″) would return ’22/05/2004′
Msgbox DateAdd(“m”, 5, “22/11/2003″) would return ’22/04/2004′
—-

Date  ’ returns current system date eg. 5/4/2012  (5th april, 2012)

Msgbox Date()

—-
Format(Date, “yyyy/mm/dd”) ’ returns date as “2012/04/05″

s = (Format(#4/17/2004#, “yyyy/mm/dd”))
MsgBox s                                                                                  ‘ returns date as “2004/04/17″
—-
MsgBox MonthName(3, True)   ’Would return ‘Mar’
MsgBox MonthName(7, FALSE)   ’would return ‘July’
 
—-
MsgBox  TimeSerial(20 – 8, 6, 30)  ’would return 12:06:30 PM

—-

now    ’ would return mm/dd/yyyy hh:mm:ss [AM|PM]

—-

MonthName(3, TRUE)  ’ would return ‘Mar’
MonthName(7, FALSE)  ’ would return ‘July’

—-
WeekdayName(3, TRUE, vbMonday)  ’ would return ‘Wed’
WeekdayName(3, TRUE, 2)  ’ would return ‘Wed’

—-

msgbox Year(#5/4/2012#)                    ‘ would return “2012″

One Comment

  1. hey it was a good post thanks for posting, please keep postinghttp://www.capitaocaverna.net

Leave a Reply

Required fields are marked *.

*