Click to See Complete Forum and Search --> : Date Difference Commputing
Bitter
Dec 29th, 1999, 03:39 PM
Please help Me!
I'm Programmer beginner and I use VB6. Here is mine problem.
I set following variables:
Date1 - presenting current date in format "dd.mm.yyyy."
Date2 - presenting end date also in format "dd.mm.yyyy."
Date3 - presenting difference between current date and end date
Wenn I use relationship Date3 = Date2 - Date1 in order to calculate difference between 15.12.1999. and 05.01.2000. I get negative number (-10). Same situation is wenn I use Date3 = DateDiff("d", Date1, Date2).
What must I do to get correct date difference?
Thank You!
QWERTY
Dec 29th, 1999, 04:00 PM
The code you have posted seems to be correct for me. Are you sure that date1 is the earlier date than date2? Because for me the only way to get negative number is to calculating time from now to the past.
------------------
Visual Basic Programmer
------------------
PolComSoft
You will hear a lot about it.
RogerH
Dec 29th, 1999, 04:08 PM
Hi,
I didn't quite understand your problem, but this works:
Dim Date1 As Date
Dim Date2 As Date
Date1 = DateValue("15.12.1999")
Date2 = DateValue("05.01.2000")
MsgBox DateDiff("d", Date1, Date2)
MsgBox Abs(DateDiff("d", Date2, Date1))
RogerH
Mark Sreeves
Dec 29th, 1999, 04:15 PM
What regional settings are you using?
I see from your profile that you live in Croatia. I set my PC to Croatian settings and the only date format suggested is yyyy.MM.dd or yy.MM.d for short date and yyyy.MMMM.dd for long date.
When using dates it's best to make sure that the values you enter match the regional settings.
15.12.1999 can only be 15th December
whereas
05.01.2000 could be 5th January or 1st of May depending on your regional settings
However, the following code works ok on Croatian settings
Option Explicit
Private Sub Command1_Click()
Dim Date1 As Date
Dim Date2 As Date
Dim date3 As Integer
Date1 = "1999.12.15"
Date2 = "2000.01.05"
date3 = DateDiff("d", Date1, Date2)
End Sub
------------------
Mark Sreeves
Analyst Programmer
Mark.Sreeves@Softlab.co.uk
A BMW Group Company
Bitter
Dec 29th, 1999, 04:23 PM
Thank You Guy to all.
Happy New Year!
------------------
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.