Dates
am 06.12.2007 19:44:18 von addanki007Do 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
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
addanki007@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=20${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
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
On Dec 6, 12:44 pm, addanki...@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)}'
On Thu, 6 Dec 2007 10:44:18 -0800 (PST), addanki007@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() { #
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=20${input#*Q}-$1
qtr_last_mnth_end=20${input#*Q}-$2
echo "$qtr_first_mnth_end and $qtr_last_mnth_end"
}
--
Stephane