Skip to main content

hello,

 

if you have a date: 01-01-2018

and you have a date1 10-10-2018

 

how would you then make a script which always validate that date1 is minimum 30days earlier than the normal date?


#Rumba

hello,

 

if you have a date: 01-01-2018

and you have a date1 10-10-2018

 

how would you then make a script which always validate that date1 is minimum 30days earlier than the normal date?


#Rumba
Hi besafe,

Sub besafe2()
MyDifference = DateValue(Sheet1.Cells(2, 1)) - DateValue(Sheet1.Cells(1, 1))
If MyDifference < 0 Then
MsgBox "(R1:C1) is more recent than (R2:C1)" & Chr$(13) & Chr$(10) & "Day Delta = " & Abs(MyDifference)
ElseIf MyDifference > 0 Then
MsgBox "(R1:C1) is older than (R2:C1)" & Chr$(13) & Chr$(10) & "Day Delta = " & MyDifference
Else
MsgBox "(R1:C1) and (R2:C1) as the same date" & Chr$(13) & Chr$(10) & "Day Delta = " & MyDifference
End If
End Sub

Cheers,
Tom

hello,

 

if you have a date: 01-01-2018

and you have a date1 10-10-2018

 

how would you then make a script which always validate that date1 is minimum 30days earlier than the normal date?


#Rumba
Dim betwDates As Integer
betwDates = DateDiff("d", exampleDate1, exampleDate2)

'gives you the number of days between two dates

hello,

 

if you have a date: 01-01-2018

and you have a date1 10-10-2018

 

how would you then make a script which always validate that date1 is minimum 30days earlier than the normal date?


#Rumba
Dim betwDates As Integer
betwDates = DateDiff("d", exampleDate1, exampleDate2)

'gives you the number of days between two dates

hello,

 

if you have a date: 01-01-2018

and you have a date1 10-10-2018

 

how would you then make a script which always validate that date1 is minimum 30days earlier than the normal date?


#Rumba
i may get you wrong but when i tried to use it, i kept giving me errors:

Dim betwDates As Integer
Dim exampledate1 as integer
Dim exampledate2 as integer
emreadscreen exampleDate1,10,17,39
emreadscreen exampleDate2,10,16,30
betwDates = DateDiff("d", exampleDate2, exampleDate1)

emsetcursor 22,6
emsendkey betwDates

again i may be totally wrong

hello,

 

if you have a date: 01-01-2018

and you have a date1 10-10-2018

 

how would you then make a script which always validate that date1 is minimum 30days earlier than the normal date?


#Rumba
Hi besafe,

you need to line up your days months and years which the correct delimiter. Here is a sample.

Sub Main

Dim betwDates As Integer
Dim exampleDate1 as String
Dim exampleDate2 as String

emreadscreen exampleDate1,10,20,09
emreadscreen exampleDate2,10,20,20

'On teh host screen my date appear as say "20-06-2018"
'My locales format is Month/Day/Year e.g. "06-20-2018"
'So I need to get my YYYY, MM and DD lined up and switch from "-" to "/" which is what my FormatDate function does.

exampleDate1 = FormatDate(exampleDate1)
exampleDate2 = FormatDate(exampleDate2)

betwDates = DateDiff("d", exampleDate2, exampleDate1)
Msgbox betwDates
emsetcursor 20,31
emsendkey betwDates

End Sub

Function FormatDate(exampleDate as String) as String
Dim NewDate as String
NewDate = Right(exampleDate, 4) & "/" & Left(exampleDate, 2) & "/" & Mid(exampleDate, 4, 2)
FormatDate = NewDate
End Function

hello,

 

if you have a date: 01-01-2018

and you have a date1 10-10-2018

 

how would you then make a script which always validate that date1 is minimum 30days earlier than the normal date?


#Rumba

hello Tom, the latest script you gave me worked perfectly... at first but now i keep on getting the error "overflow" do you know why this happens?

 


Sub Main

Dim betwDates As Integer
Dim exampleDate1 as String
Dim exampleDate2 as String

emreadscreen exampleDate1,10,16,18
emreadscreen exampleDate2,10,17,39

 

'On teh host screen my date appear as say "20-06-2018"
'My locales format is Month/Day/Year e.g. "06-20-2018"
'So I need to get my YYYY, MM and DD lined up and switch from "-" to "/" which is what my FormatDate function does.

exampleDate1 = FormatDate(exampleDate1)
exampleDate2 = FormatDate(exampleDate2)

emsetcursor 22,6


betwDates = DateDiff("d", exampleDate2, exampleDate1)
Msgbox betwDates
emsetcursor 22,6
emsendkey betwDates

End Sub

Function FormatDate(exampleDate as String) as String
Dim NewDate as String
NewDate = Right(exampleDate, 4) & "/" & Left(exampleDate, 2) & "/" & Mid(exampleDate, 4, 2)
FormatDate = NewDate
End Function


hello,

 

if you have a date: 01-01-2018

and you have a date1 10-10-2018

 

how would you then make a script which always validate that date1 is minimum 30days earlier than the normal date?


#Rumba
so i read somewhere else online that the reason that it was overflowing was that the answer could be bigger than 33000 which it couldn't handle, however you could use the variable declaration "long" it should handle it. i can see that the number i get is 43112, however the answer should be much smaller since the dates im comparing is 01-12-2018 and 18-04-2018 can you please tell me what is happening

hello,

 

if you have a date: 01-01-2018

and you have a date1 10-10-2018

 

how would you then make a script which always validate that date1 is minimum 30days earlier than the normal date?


#Rumba
i found the answer im not sure why or how but i got the answer :D

hello,

 

if you have a date: 01-01-2018

and you have a date1 10-10-2018

 

how would you then make a script which always validate that date1 is minimum 30days earlier than the normal date?


#Rumba
Does is look like this?

Function FormatDate(exampleDate as String) as String
Dim NewDate as String
NewDate = Left(exampleDate, 2) & "/" & Mid(exampleDate, 4, 2) & "/" & Right(exampleDate, 4)
FormatDate = NewDate
End Function

Cheers,
Tom