(Video materials in preparation)
mdate : Performs date calculations
Usage:
DIRECT-MODE
Date mdate <yyyymmdd> : date
mdate -dow <yyyymmdd> : day of the week
mdate -w <yyyymmdd> : week
mdate <yyyywwdd>/±<dif> : date ahead of <dif> days
mdate -e <yyyywwdd>/±<dif> : dates ahead of <dif> days in a row
mdate <yyyymmdd1> <yyyymmdd2> : difference of dates
mdate -e <yyyymmdd1> <yyyymmdd2> : a range of dates in a row
mdate -ly <yyyymmdd> : same day one year earlier
mdate -lyw <yyyymmdd> : same week one year earlier
Week mdate <yyyyww>w : week
mdate -d <yyyyww>w : one week date
mdate <yyyyww>w/±<dif> : week ahead of <dif> weeks
mdate -e <yyyyww>w/±<dif> : weeks ahead of <dif> weeks in a row
mdate <yyyyww1>w <yyyyww2>w : difference of weeks
mdate -e <yyyyww1>w <yyyyww2>w : a range of weeks in a row
mdate -ly <yyyyww>w : a week one year earlier
Month mdate <yyyymm>m : month
mdate -d <yyyymm>m : one month date
mdate <yyyymm>m/±<dif> : month ahead of <dif> months
mdate -e <yyyymm>m/±<dif> : months ahead of <dif> in a row
mdate <yyyymm1>m <yyyymm2>m : difference of months
mdate -e <yyyymm1>m <yyyymm2>m : a range of months in a row
mdate -ly <yyyymm>m : same month one year earlier
FILTER-MODE
Date mdate -f -dow <f> : day of the week
mdate -f -w <f> : week
mdate -f <f>/±<dif> : date ahead of <dif> days
mdate -f -e <f>/±<dif> : dates ahead of <dif> days in a row
mdate -f <f1> <f2> : difference of dates
mdate -f -e <f1> <f2> : a range of dates in a row
mdate -f <f1> +<f2> : addition of date
mdate -f -e <f1> +<f2> : addition of dates in a row
mdate -f -ly <f> : date one year earlier
mdate -f -lyw <f> : same week day one year earlier
Week mdate -f -d <f>w : one week dates
mdate -f <f>w/±<dif> : week ahead of <dif> week
mdate -f -e <f>w ±<dif> : week ahead of <dif> weeks in a row
mdate -f <f1>w <f2>w : difference of weeks
mdate -f -e <f1>w <f2>w : a range of weeks in a row
mdate -f <f>w +<f2> : addition of week
mdate -f -e <f>w +<f2> : addition of weeks in a row
mdate -f -ly <f>w : same week one year earlier
Month mdate -f -d <f>w : one month dates
mdate -f <f>m/±<dif> : month ahead of <dif> month
mdate -f -e <f>m ±<dif> : month ahead of <dif> months in a row
mdate -f <f1>m <f2>m : difference of months
mdate -f -e <f1>m <f2>m : a range of months in a row
mdate -f <f>m +<f2> : addition of month
mdate -f -e <f>m +<f2> : addition of months in a row
mdate -f -ly <f>m : same month one year earlier
Version : Tue Jan 9 09:02:34 JST 2024
Edition : 2
The week functions only work when MDWEEKTABLE exists. (described
later)
Prints Date, Day of Week, Month:
$ mdate 20090912
20090912 <-- Prints as-is
$ mdate -y 20090912
6 <-- 1:Mon 2:Tue 3:Wed 4:Thu 5:Fri 6:Sat 7:Sun
$ mdate 200901w
200901 <-- Prints as-is
$ mdate 200909m
200909 <-- Prints as-is
$ mdate -d 200909m
20090901 20090902 20090903 .... 20090927 20090928 20090929 20090930
Prints Date, Month +/- <dif>
$ mdate 20090912/+5
20090917
$ mdate 200907w/+5
200912
$ mdate 200909m/+5
201002
Prints all Dates or Months +/- <dif>
$ mdate -e 20090912/+5
20090912 20090913 20090914 20090915 20090916 20090917
$ mdate -e 20090912/-5 <-- Prints in order from earliest date
20090907 20090908 20090909 20090910 20090911 20090912
$ mdate -e 200909m/+5
200909 200910 200911 200912 201001 201002
$ mdate -e 200909m/-5 <-- Prints in order from earliest month
200904 200905 200906 200907 200908 200909
Prints difference between Dates or Months
$ mdate 20090917 20090912
5
$ mdate 201002m 200909m
5
Prints consecutive Dates or Months in a range
$ mdate -e 20090912 20090917
20090912 20090913 20090914 20090915 20090916 20090917
$ mdate -e 20090917 20090912 <-- Prints in order from earliest date
20090912 20090913 20090914 20090915 20090916 20090917
$ mdate -e 200909m 201002m
200909 200910 200911 200912 201001 201002
$ mdate -e 201002m 200909m <-- Prints in order from earliest month
200909 200910 200911 200912 201001 201002
Inserts Date and Month.
$ cat date_data
A 20090901 B
A 20090902 B
A 20090903 B
$ mdate -f -y 2 date_data <-- Inserts Day of Week
A 20090901 2 B
A 20090902 3 B
A 20090903 4 B
$ cat month_data
A 200909 B
A 200910 B
A 200911 B
$ mdate -f -d 2m month_data
A 200909 20090901 ... 20090927 20090928 20090929 20090930 B
A 200910 20091001 ... 20091027 20091028 20091029 20091030 20091031 B
A 200911 20091101 ... 20091127 20091128 20091129 20091130 B
Inserts Date or Month +/- <dif>
$ cat date_data
A 20090901 B
A 20090902 B
A 20090903 B
$ mdate -f 2/+5 date_data
A 20090901 20090906 B
A 20090902 20090907 B
A 20090903 20090908 B
$ mdate -f 2/-5 date_data
A 20090901 20090827 B
A 20090902 20090828 B
A 20090903 20090829 B
$ cat month_data
A 200909 B
A 200910 B
A 200911 B
$ mdate -f 2m/+5 month_data
A 200909 201002 B
A 200910 201003 B
A 200911 201004 B
$ mdate -f 2m/-5 month_data
A 200909 200904 B
A 200910 200905 B
A 200911 200906 B
Inserts consecutive Dates, Weeks or Months +/- <dif>
$ cat date_data
A 20090901 B
A 20090902 B
A 20090903 B
$ mdate -f -e 2/+5 date_data
A 20090901 20090902 20090903 20090904 20090905 20090906 B
A 20090902 20090903 20090904 20090905 20090906 20090907 B
A 20090903 20090904 20090905 20090906 20090907 20090908 B
$ mdate -f -e 2/-5 date_data
A 20090827 20090828 20090829 20090830 20090831 20090901 B
A 20090828 20090829 20090830 20090831 20090901 20090902 B
A 20090829 20090830 20090831 20090901 20090902 20090903 B
$ cat month_data
A 200909 B
A 200910 B
A 200911 B
$ mdate -f -e 2m/+5 month_data
A 200909 200910 200911 200912 201001 201002 B
A 200910 200911 200912 201001 201002 201003 B
A 200911 200912 201001 201002 201003 201004 B
$ mdate -f -e 2m/-5 month_data
A 200904 200905 200906 200907 200908 200909 B
A 200905 200906 200907 200908 200909 200910 B
A 200906 200907 200908 200909 200910 200911 B
Inserts difference between Dates or Months
$ cat date_data2
A 20091001 20090901 B
A 20091003 20090902 B
A 20091005 20090903 B
$ mdate -f 2 3 date_data2
A 20091001 20090901 30 B
A 20091003 20090902 31 B
A 20091005 20090903 32 B
$ cat month_data2
A 200909 200810 B
A 200911 200811 B
A 201001 200812 B
$ mdate -f 2m 3m month_data2
A 200909 200810 11 B
A 200911 200811 12 B
A 201001 200812 13 B
Inserts all Dates or Months between two Dates, Weeks or Months
$ cat date_data2
A 20090905 20090901 B
A 20090904 20090902 B
A 20090906 20090903 B
$ mdate -f -e 2 3 date_data2
A 20090905 20090901 20090901 20090902 20090903 20090904 20090905 B
A 20090904 20090902 20090902 20090903 20090904 B
A 20090906 20090903 20090903 20090904 20090905 20090906 B
$ cat month_data2
A 200901 200810 B
A 200903 200811 B
A 200904 200812 B
$ mdate -f -e 2m 3m month_data2
A 200901 200810 200810 200811 200812 200901 B
A 200903 200811 200811 200812 200901 200902 200903 B
A 200904 200812 200812 200901 200902 200903 200904 B
Add Dates or Months
$ cat date_data4
A 20090901 1 B
A 20090902 2 B
A 20090903 3 B
$ mdate -f 2 +3 date_data4
A 20090901 1 20090902 B
A 20090902 2 20090904 B
A 20090903 3 20090906 B
$ cat month_data4
A 200911 1 B
A 200912 2 B
A 201001 3 B
$ mdate -f 2m +3 month_data4
A 200911 1 200912 B
A 200912 2 201002 B
A 201001 3 201004 B
Insert all Dates or Months +/- <dif>
$ cat date_data4
A 20090901 1 B
A 20090902 2 B
A 20090903 3 B
$ mdate -f -e 2 +3 date_data4
A 20090901 1 20090901 20090902 B
A 20090902 2 20090902 20090903 20090904 B
A 20090903 3 20090903 20090904 20090905 20090906 B
$ cat month_data4
A 200911 1 B
A 200912 2 B
A 201001 3 B
$ mdate -f -e 2m +3 month_data4
A 200911 1 200911 200912 B
A 200912 2 200912 201001 201002 B
A 201001 3 201001 201002 201003 201004 B
To use the week function, MDWEEKTABLE files should be created. The
path of MDWEEKTABLE is ~/TBL/MDWEEKTABLE.
MDWEEKTABLE is the table to manage the week number. It consist of
the date field and the week number field. All dates should be
contiguous. Week numbers are 1 through 7 digits arbitraly integer.
All week numbers should be same digits, but no need to be contiguous
nor in ascending order.
MDWEEKTABLE.SAMPLE is offered for the example. this file is created
in the condition "weeks started on Monday, the week including 1st
March is the 1st week of a fiscal year. Take care of that the
condition of the week nunber is differ on companies or industry
types.
$ head ~/TBL/MDWEEKTABLE
20050228 200501
20050301 200501
20050302 200501
20050303 200501
20050304 200501
20050305 200501
20050306 200501
20050307 200502
20050308 200502
20050309 200502
Print week number.
$ mdate 200901w
200901 <-- Prints in order from earliest date
$ mdate -d 200901w
20090223 20090224 20090225 20090226 20090227 20090228 20090301
Calculate on week numbers.
$ mdate 200907w/+5
200912
Prints weeks ahead of <dif> weeks in a row.
$ mdate -e 200909w/+5
200909 200910 200911 200912 200913 200914
$ mdate -e 200909w/-5 <-- prins earlier week to later
200904 200905 200906 200907 200908 200909
Prints the difference of weeks.
$ mdate 200909w 200902w
7
Prints the range of dates in a row.
$ mdate -e 200909w 200907w
200907 200908 200909
$ mdate -e 200907w 200909w <-- prins earlier week to later
200907 200908 200909
The filter mode works in similar way.
"today", "yesterday", "yday", "tomorrow", "nday" can be specified
for <yyyymmdd>.
"thisweek" can be specified for <yyyyww>.
"thismonth" can be specified for <yyyymm>.