|
-
Dec 29th, 1999, 04:39 PM
#1
Thread Starter
New Member
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!
-
Dec 29th, 1999, 05:00 PM
#2
Fanatic Member
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.
-
Dec 29th, 1999, 05:08 PM
#3
Lively Member
Hi,
I didn't quite understand your problem, but this works:
Code:
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
-
Dec 29th, 1999, 05:15 PM
#4
Frenzied Member
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
Code:
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
[email protected]
A BMW Group Company
-
Dec 29th, 1999, 05:23 PM
#5
Thread Starter
New Member
Thank You Guy to all.
Happy New Year!
------------------
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|