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

Setting Date Problem

Hi guys I have a problem with setting a date.  I am defining two starting dates and then trying to calculate an ending date automatically.

I first define my two starting dates (dd/mm/yyyy    Australian format):

dim startDate01 as date = "1/07/2004"
dim startDate02 as date = "1/08/2004"

then I want an ending date for 'StartDate01' - this has to be '30/07/2004'

so I do the following:

dim endDate01 as date = DateAdd("d", -1, startDate02)

and the result I get is:

'30/07/2009'

So the day and month calculation is correct but why is my year now incremented by 5 years?

0
jakekula
Asked:
jakekula
4 Solutions
 
razoCommented:
it worked perfectly fine
by the way it shoulld give 31/07/2004
can u post all ur code
0
 
123654789987Commented:
This code gave me the right answer.

Try this

Dim startDate01 As Date = "07/01/2004"
        Dim startDate02 As Date = "08/01/2004"

        Dim endDate01 As Date = DateAdd("d", -1, startDate02)

        MessageBox.Show(endDate01.ToString)


As u see I have changed the format of the startDate. It is expecting the date to be in this format
0
 
razoCommented:
i used the australian format and it worked...so i think the error is caused b something else
0
 
Farzad AkbarnejadCommented:
Hello,
I tested with English (Austrial) in Regional Settings in Control panel and got:  31/07/2004.
post your code here and let us know your Regional Settings of your Control Panel.

Thanks
-FA
0
 
jakekulaAuthor Commented:
Thanks guys, the problem was actually something else, I'll split the point between the four of you.

Cheers,

JK
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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