LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 05-03-2009, 10:12 AM   #1
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,546

Rep: Reputation: 50
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?
 
Old 05-03-2009, 10:13 AM   #2
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,546

Original Poster
Rep: Reputation: 50
Quote:
Originally Posted by frenchn00b View Post
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"
 
Old 05-03-2009, 10:32 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
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.

???
 
Old 05-03-2009, 02:03 PM   #4
frenchn00b
Senior Member
 
Registered: Jun 2007
Location: E.U., Mountains :-)
Distribution: Debian, Etch, the greatest
Posts: 2,546

Original Poster
Rep: Reputation: 50
Quote:
Originally Posted by pixellany View Post
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?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to calculate time difference in milliseconds in C/C++ waqasdaar Programming 19 03-17-2009 04:02 PM
OpenOffice.org Calc formula to check if day is last day of the month win32sux Linux - Software 1 01-19-2009 12:38 PM
Hi! Using rock solid Debian Etch, day to day, I'm investigating Lenny using another BillAp Linux - Newbie 2 11-26-2008 09:51 AM
Machine boots one day, the next day it won't (is my power supply dying?). odiseo77 Linux - General 12 12-18-2007 10:00 AM
Bash time of day processing keith.brown Programming 1 05-18-2007 08:06 PM


All times are GMT -5. The time now is 07:28 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration