Project 2002 : Comparing dates problem

B

BIG Chris

Hi,

In VBA I have a problem in comparing two "dates" because:

tsk.Start gives you a date as "01/06/2004 08:00:00", which is fine.

But

tsk.GetField(pjTaskStart) gives you a date as "Tue 01/06/04".

I can't format this using the Format or FormatDateTime functions because it
isn't recognised as a date. I don't think I can simply chop one end off the
string and then format it because I suspect the format may be different
depending on the user's locale settings - but I can't seem to find out any
more info about this anywhere.

NB. Tsk is assigned to a MS project task

I did have the crazy idea of changing the date format via the
Tools/Options/View dialog; but that's no good as this is set as standard. If
there is anyway in code to temporarily change this ( & change it back
afterwards ) then that might be a dirty solution ... but it's better than
nothing !! Though if someone has a better idea, I would be grateful ( I've
tried using Cdate but that doesn't seem to work either ).

Any Ideas ?

Cheers,

BIG Chris.
 
J

Jan De Messemaeker

Hi,

It's not a dirty solution, it is THE solution.
Lookup the help for Defaultdateformat method

OBTW what is "dirty" in my opinion is working with fields (a opposed to MS
project objects) in Project VBA but I suppose you must have a good reason to
go that way?
HTH
 
J

John

Chris,
Exactly what problem are you having comparing dates? I did a quick test
using the DateDifference function with Project set to display the Start
date in a format that includes the day. The function works fine because
date comparison functions actually work in minutes. What you see on the
display (i.e. view) is strictly formatting for visual presentation. So
from my view you don't need the approach you call "dirty". By the way,
in my opinion there is no such thing as a "dirty" solution. Since I tend
to think outside the box, by your definition I suppose a good portion of
my solutions are "dirty". If the solution to a problem gets the answer,
it's not "dirty" it more likely is unconventionally clever (unless there
is a much simpler conventional approach).

Here is another out-of-the-box solution. Regardless of format, there are
three functions that will return the info you want:
Year, Month and Day. Once you have these three pieces of information you
can do whatever you need.

Another viewpoint.
John
 
B

BIG Chris

John,

Thanks for the info ... sorry it's taken me a while to respond, but I forgot
that I set this newsgroup up without my email address, but was waiting for
the replies in my inbox !!

Anyway, I tried using the DateDifference as you suggested, but I'm not sure
if I'm using it correctly as it doesn't seem to work for me :

? ActiveProject.Tasks(10).Start
10/07/2003 17:00:00

? ActiveProject.Tasks(11).GetField(pjTaskStart)
Fri 11/07/03

but

?
application.DateDifference(ActiveProject.Tasks(10).Start,ActiveProject.Tasks(11).GetField(pjTaskStart))
0

I would have expecte the above to return something other than '0' ??

Cheers,

Chris.
 
J

JackD

5 PM on 10/07/2003 is 0 working minutes different from 12::00AM on 11/07/03.
That is why you have a zero for the result.

Why don't you use
application.DateDifference(ActiveProject.Tasks(10).Start,ActiveProject.Tasks
(11).Start)?

That should give you better results regardless of the date format which is
used.

-Jack
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top