Hi,Dim ReqdDate As New NotesDateTime( Format(note.DateReqd(0),“dd/mm/yyyy”))
Dim ThisDay As New NotesDateTime(Format(Today,“dd/mm/yyyy”))
temp=ReqdDate.TimeDifference( ThisDay )
I am using this code to find the time difference in a scheduled agent to sent some mail
But ReqdDate value is coming in mm/dd/yyyy
while thisday is coming in dd/mm/yyyy format
Because of this issue temp is having negative value…
Field format of ReqdDate is mm/dd/yyyy
Can anyone help in converting ReqdDate to dd/mm/yyyy
Cheers
Merrin
Subject: Needed help in changing date format
Question #1 (I’m guessing I know the answer), what is note.DateReqD? A true Notes Date Time or is it Text?
When working with NotesDateTime, you don’t need to worry about the format of the data time (mm/dd/yyyy or dd/mm/yyyy) as notes stores the values as numbers.
Therefore your code should just be:
Dim ReqdDate As New NotesDateTime( note.DateReqd(0) )
Dim ThisDay As New NotesDateTime( Today & " 12:00:00 AM" )
temp=ReqdDate.TimeDifference( ThisDay )
The value of temp can be negative if ThisDay is less that ReqdDate.
Also, FYI there use to be a problem if you only gave a DateTime value without a time. Therefore it’s always best to incldue the time and AFAIR Today only returns today’s date.
If your DateReqd value is a string, then you will need to parse it and use the function date( y, m, d) to get a proper datetime.
The problem is if someone create a document using different regional settings. For example my date format is yyyy-mm-dd so if I ran your code it would generate an error on the Dim as the format you specify is invalid for my regional settings.
Subject: Needed help in changing date format
Hey Merrin,
I would suggest that you verify that your data contains dates and not strings that look like dates. Your strategy of using NotesDateTime objects for doing the comparision is absolutely correct, but your practice of converting the data to strings is a very bad idea.
Try this approach instead
Dim ReqdDate as NotesDateTime
Dim ThisDay as NotesDateTime
Dim diff as Double
If Not note.DateReqd(0).DateTimeValue is Nothing Then
Set ReqdDate = note.DateReqd(0).DateTimeValue
Set ThisDay = new NotesDateTime(Now())
diff = ReqdDate.TimeDifferenceDouble(ThisDay)
End If
It offers the advantage that the date is never converted from one data type to another, which is always a risky prospect at the best of times and particularly dangerous with dates.
HTH
Subject: Needed help in changing date format
I removed format function and Now it is workingThank you both