Dates
Do you have a sample code that calculates QTR_FIRST_MNTH_END and
QTR_LAST_MNTH_END if we pass 1Q07
output should be 2007-01-31 and 2007-03-31
Thanks in advance
Re: Dates
addanki007 [at] gmail.com wrote:
> Do you have a sample code that calculates QTR_FIRST_MNTH_END and
> QTR_LAST_MNTH_END if we pass 1Q07
A less cryptic description would have been more appropriate.
Here's some sample code...
qy=1Q07
q=${qy%Q*}
y ${qy#*Q}
m3=$((q*3))
m1=$((m3-2))
d1=$( cal $m1 $y | awk 'NF{x=$NF}END{print x}' )
d3=$( cal $m3 $y | awk 'NF{x=$NF}END{print x}' )
printf "%04d-%02d-%02d\n" $y $m1 $d1 $y $m3 $d3
Janis
> output should be 2007-01-31 and 2007-03-31
> Thanks in advance
Re: Dates
On Thu, 06 Dec 2007 10:44:18 -0800, addanki007 wrote:
> Do you have a sample code that calculates QTR_FIRST_MNTH_END and
> QTR_LAST_MNTH_END if we pass 1Q07
> output should be 2007-01-31 and 2007-03-31 Thanks in advance
A tested awk script:
$ awk -v q="1Q07" '
BEGIN {
split("01-31,03-31:04-30,06-30:07-31,09-30:10-31,12-31", quarters, ":")
split(q, t, "Q")
split(quarters[t[1]], ts, ",")
printf "20%02d-%s 20%02d-%s\n", t[2], ts[1], t[2], ts[2]
}'
2007-01-31 2007-03-31
$
Regards,
Steffen "goedel" Schuler
Re: Dates
On Dec 6, 12:44 pm, addanki... [at] gmail.com wrote:
> Do you have a sample code that calculates QTR_FIRST_MNTH_END and
> QTR_LAST_MNTH_END if we pass 1Q07
> output should be 2007-01-31 and 2007-03-31
> Thanks in advance
ruby -rdate -ne 'q,y=split(/Q/)
puts [2,0].map{|o|
Date.new(y.to_i+2000, q.to_i*3-o, -1)}'
Re: Dates
On Thu, 6 Dec 2007 10:44:18 -0800 (PST), addanki007 [at] gmail.com wrote:
> Do you have a sample code that calculates QTR_FIRST_MNTH_END and
> QTR_LAST_MNTH_END if we pass 1Q07
> output should be 2007-01-31 and 2007-03-31
> Thanks in advance
get_qtr_end_months() { # <quarter>Q<year> (qQyy)
input=$1
set 01-31 03-31 04-01 06-30 07-01 09-30 10-01 12-31
shift "$(((${input%Q*} - 1) * 2))"
qtr_first_mnth_end ${input#*Q}-$1
qtr_last_mnth_end ${input#*Q}-$2
echo "$qtr_first_mnth_end and $qtr_last_mnth_end"
}
--
Stephane