Date Difference Function

Erne ernestogiannotta at tiscalinet.it
Sun Jul 3 17:09:43 CDT 2005


Hello list,

I have a task but can't figure out how to accomplish it easily,
maybe somebody has idea

I need to know how many days separate a recurrence (stored as  
DateField) from today
e.g.
DateFormat is kMDY
Separatore is /
the recurrence is 01/03/1958
and today is 12/03/2005

the DateDiff(day) function returns -17501 which is correct but it's  
not what I'm looking for
I need the days that separate us from the recurrence on a yearly basis

so I set up a method LongField:
//  this part will return a date with the same moth and day of stored  
recurrence but with current year
RecurrenceDate ="Concat(DatePart(DateField, 'month', '/',_
                  DatePart(DateField, 'day', '/',_
                  DatePart(GetDate(CurDate()), 'year'))"
//  here we get the difference in days
DiffMethod = "DateDiff(" + RecurrenceDate + "GetDate(CurDate()), 'day')"

this will return -334 and it's still correct, but not yet what I want

I need 31 and here's how I get it:

//  this part will return a date with the same moth and day of stored  
recurrence but with current year
RecurrenceDate ="Concat(DatePart(DateField, 'month', '/',_
                  DatePart(DateField, 'day', '/',_
                  DatePart(GetDate(CurDate()), 'year')_
                  + if(DatePart(DateField, 'month') > DatePart(GetDate 
(CurDate()), 'month'), 0, 1))" <--- add 1 year if needed
//  here we get the difference in days
DiffMethod = "DateDiff(" + RecurrenceDate + "GetDate(CurDate()), 'day')"

but still this won't work well in case we are in same month, so it  
must be:

RecurrenceDate = "Concat(DatePart(DateField, 'month', '/'," +_
                  "', DatePart(DateField, 'day', '/'," +_
                  "', DatePart(GetDate(CurDate()), 'year')" +_
                  ") + if(DatePart(DateField, 'month') > DatePart 
(GetDate(CurDate()), 'month'), " +_
                  "0, if(DatePart(DateField, 'month') = DatePart 
(GetDate(CurDate()), 'month'), " +_
                  "if(DatePart(DateField, 'day') >= DatePart(GetDate 
(CurDate()), 'day'), 0, 1), 1)))"
DiffMethod = "DateDiff(" + RecurrenceDate + ", GetDate(CurDate()),  
'day')"


Am I mad?
Is there any simpler way to accomplish this in the opinion of those  
brave enough to follow me up to here :?)

thanks for your kind attention



Cool Runnings,
Erne.

/ |\ |\  | /
– |/ | \ | –
\ |\ |  \| \



More information about the Valentina mailing list