Home > Archive > AWK > March 2006 > Manipulating dates
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Manipulating dates
|
|
| mickey 2006-03-27, 6:56 pm |
| Hi,
I am trying to do a little text processing and was able to do everything
until this problem. I have a date variable in a file in the form of
dd-mmm-yyyy, eg, 27-Sep-2001. I would like to find the difference in
months between this and some other date, like 1-Jan-1999. Is there a way
to handle this in gawk?
Thanks,
-M
| |
| Ed Morton 2006-03-28, 3:56 am |
| mickey wrote:
> Hi,
>
> I am trying to do a little text processing and was able to do everything
> until this problem. I have a date variable in a file in the form of
> dd-mmm-yyyy, eg, 27-Sep-2001. I would like to find the difference in
> months between this and some other date, like 1-Jan-1999. Is there a way
> to handle this in gawk?
>
> Thanks,
> -M
This will print the number of seconds between 2 date/time values given
in some non-standard 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)
}
See the mktime() entry in the gawk man page and change the
format/granularity to suit your needs.
Regards,
Ed.
| |
| mickey 2006-03-28, 6:56 pm |
| Ed Morton wrote:
> mickey wrote:
>
>
>
> This will print the number of seconds between 2 date/time values given
> in some non-standard 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)
> }
>
> See the mktime() entry in the gawk man page and change the
> format/granularity to suit your needs.
>
> Regards,
>
> Ed.
THanks a lot.
-M
|
|
|
|
|