LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   bash: time difference and calculate the mid day of the day? (http://www.linuxquestions.org/questions/programming-9/bash-time-difference-and-calculate-the-mid-day-of-the-day-723314/)

frenchn00b 05-03-2009 11:12 AM

bash: time difference and calculate the mid day of the day?
 
Hello,

In bash how to make the time difference and calculate the mid day of the day?

frenchn00b 05-03-2009 11:13 AM

Quote:

Originally Posted by frenchn00b (Post 3528503)
Hello,

In bash how to make the time difference and calculate the mid day of the day?

solved, fast.
I wanna share it actually.

So all in one :
Code:

#!/bin/bash
weatherget  -s XXXXXX --metric > /tmp/weatherindi.tmp
timegot1=` cat /tmp/weatherindi.tmp  | grep Sunrise |  cut -d':' -f2-4 `
timegot2=` cat /tmp/weatherindi.tmp | grep Sunset |  cut -d':' -f2-4 `
start=`date +%s -d "$timegot1"`
end=`date +%s -d "$timegot2"`
timediff=`echo "$end - $start" | bc`
timediffsur2=`echo "($end - $start)/2" | bc`
timediffmid=`echo "$start + $timediffsur2" | bc`
thehour=`date +%H --date=@"$timediff"`
themin=`date +%M --date=@"$timediff" `
themiddayh=`date +%H --date=@"$timediffmid" `
themiddaym=`date +%M --date=@"$timediffmid" `
echo "`date +%H:%M --date=@$start`  `date +%H:%M --date=@$end`  ${thehour}H${themin} and the mid day is  ${themiddayh}H$themiddaym"


pixellany 05-03-2009 11:32 AM

Ummm---the "mid day" of the day--AKA middle of the day--is 12:00 noon!! The time of sunrise and sunset is variable, but a day is defined by the clock and the calendar.

Perhaps you mean the time at which the sun is directly overhead? No--that occurs only at the equinox.

The time at which the maximum elevation angle of the sun is exactly equal to the latitude? No--that only happens at the solstice.

???

frenchn00b 05-03-2009 03:03 PM

Quote:

Originally Posted by pixellany (Post 3528520)
Ummm---the "mid day" of the day--AKA middle of the day--is 12:00 noon!! The time of sunrise and sunset is variable, but a day is defined by the clock and the calendar.

Perhaps you mean the time at which the sun is directly overhead? No--that occurs only at the equinox.

The time at which the maximum elevation angle of the sun is exactly equal to the latitude? No--that only happens at the solstice.

???

I meant sun at max. overhead, so I divided sunset - sunrise / 2 ;)
solstice, equinox ...

what s the equation then to get max. sun, max UV point?


All times are GMT -5. The time now is 05:26 PM.