ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
For calculations like this, change to Unix timestamp, or seconds.
First get the TS of last Thursday in seconds: last_th=$(date -d "last Thursday" "+%s")
When you have that, substract 7 * 86400 seconds from it before_last_th=$last_th-7*86400
Get the date of that day: date -d "1970-01-01 +$before_last_th seconds" "+%F %Ts"
BTW, date is a shell command, does it exist in Perl as well? The substraction is pseudo code, adjust to your language.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
Perl does have its date/time functions, don't know if you can get something fancy like "last thursday" without complicated loops. Using the shell command seems a good idea.
Whatever, for calculations like this, using epoch time is definitely not a hassle. I wrote a complicated project in PHP which involved nothing but schedules and time calculations. I started out using datetime formats, but later I used used exclusively epoch time in calculations. Only at the presentation end I did a conversion to or from datetime.
date -d $yr$mo$da +%u' '%a' '%b' '%d' '$subdate
4 Thu Jan 02 1969
The solar cycle is usually every 28 years.
Well, you know what to do when days amd months are larger than 9.
heh
a=$( echo $( date -d $yr$mo$da +%u ))
if [ $a == 4 ]
then
echo $( date -d $yr$mo$da +%u' '%a' '%b' '%d' '$subdate )
fi
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.