To improve Calculate Number of Days Command

前端 未结 2 1770
滥情空心
滥情空心 2021-01-27 16:02

Would like to generate report, which calculate the number of days, the material is in the warehouse. The number of days is the difference between date ($3 field) t

2条回答
  •  萌比男神i
    2021-01-27 16:24

    Since you are on cygwin you are using GNU awk which has it's own built-in time functions and so you do not need to be trying to use the shell date command. Just tweak this old command I had lying around to suit your input and output format:

    function cvttime(t,     a) {
            split(t,a,"[/:]")
            match("JanFebMarAprMayJunJulAugSepOctNovDec",a[2])
            a[2] = sprintf("%02d",(RSTART+2)/3)
            return( mktime(a[3]" "a[2]" "a[1]" "a[4]" "a[5]" "a[6]) )
    }
    BEGIN{
    t1="01/Dec/2005:00:04:42"
    t2="01/Dec/2005:17:14:12"
    print cvttime(t2) - cvttime(t1)
    }
    

    It uses GNU awk for time functions, see http://www.gnu.org/software/gawk/manual/gawk.html#Time-Functions

提交回复
热议问题