4.33 diff - Calculate Interval

Format 1: diffyear($date_1,date_2$)

Format 2: diffyear($time_1,time_2$)

Format 3: diffmonth($date_1,date_2$)

Format 4: diffmonth($time_1,time_2$)

Format 5: diffday($date_1,date_2$)

Format 6: diffday($time_1,time_2$)

Format 7: diffhour($date_1,date_2$)

Format 8: diffhour($time_1,time_2$)

Format 9: diffminute($date_1,date_2$)

Format 10: diffminute($time_1,time_2$)

Format 11: diffsecond($date_1,date_2$)

Format 12: diffsecond($time_1,time_2$)

Compute the interval between two dates or time such as $date_1$($time_1$) and $date_2$($time_2$), where the interval is measured in terms of months, days, hours, minutes, seconds. Fractions are rounded up.

Examples

Example 1: Compute the interval in terms of month

Compute the number of months during the period between the value in the date column and September 1, 2013.

$ more dat1.csv
id,date
1,19641010
2,20000101
3,
4,19770812
$ mcal c='diffmonth($d{date},0d20130901)' a=rsl i=dat1.csv o=rsl1.csv
#END# kgcal a=rsl c=diffmonth($d{date},0d20130901) i=dat1.csv o=rsl1.csv
$ more rsl1.csv
id,date,rsl
1,19641010,-587
2,20000101,-164
3,,
4,19770812,-433

Example 2: Compute the interval in terms of minutes

Compute the minutes between the value in the time column and January 1, 2012 00 hours 00 minutes 00 seconds.

$ more dat2.csv
id,time
1,20120101000000
2,20120101011112
3,
4,20111231235000
$ mcal c='diffmonth($t{time},0t20120101000000)' a=rsl i=dat2.csv o=rsl2.csv
#END# kgcal a=rsl c=diffmonth($t{time},0t20120101000000) i=dat2.csv o=rsl2.csv
$ more rsl2.csv
id,time,rsl
1,20120101000000,0
2,20120101011112,0
3,,
4,20111231235000,-1