How to subtract two dates in a file to get number of days?
I have a sample file with six fields delimited by commas below:
1astname1,firsname1 , 216057926,102,07/03/10,07/04/10
lastname2,firstname2 , 211968262,105,07/01/10,07/04/10
field 5 is first date
field 6 is last date
I need to subtract field6 - field5 to get the number of days and then append it as field7 to the file. Desired result is below:
1astname1,firsname1 , 216057926,102,07/03/10,07/04/10,1
lastname2,firstname2 , 211968262,105,07/01/10,07/04/10,3
I appreciate any help.
You can simply use the date command and the bash arithmetic operator. Date differences are usually made in seconds since epoch units, then we can apply any conversion to days, hours and so on by means of the proper conversion factor. Since you don't need fractional parts of the day, bash (integer) arithmetic is enough. An example of the date command:
Thanks a lot. I was able to fix it thru this guide.
|All times are GMT -5. The time now is 02:22 PM.|