Today (Saturday) We will make some minor tuning adjustments to MySQL.

You may experience 2 up to 10 seconds "glitch time" when we restart MySQL. We expect to make these adjustments around 1AM Eastern Daylight Saving Time (EDT) US.


Get business days including today's date


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Get business days including today's date

I am trying to get last 5 business day [excluding sat and sun].
trying
Code:
for d in Mon Tue Wed Thu Fri
do
date +%Y%m%d -d "last $d"
done

gives me [provided]
Code:
date
Thu Oct 20 23:56:26 EDT 2016

Code:
20161017
20161018
20161019
20161013
20161014

expected output should be
Code:
20161017
20161018
20161019
20161020
20161014



Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 10-21-2016 at 04:52 AM.. Reason: Added CODE tags.
# 2  
Not trying to interpret your specification but just guessing what you want (for date: 21.10.16 09:57) :
Code:
{ date +%Y%m%d; for d in Mon Tue Wed Thu Fri; do date +%Y%m%d -d "last $d"; done; } | sort | tail -5
20161017
20161018
20161019
20161020
20161021

This User Gave Thanks to RudiC For This Post:
# 3  
You haven't said what operating system or shell you're using (and the date utility on my operating system doesn't support the -d option), but with a recent Korn shell, you could use:
Code:
#!/bin/ksh
dow=$(date '+%a')
for d in Mon Tue Wed Thu Fri
do
	[ $d = $dow ] && offset="now" || offset="last $d"
	#date +%Y%m%d -d "$offset"
	printf '%(%Y%m%d\n)T' "$offset"
done

If you don't have a recent Korn shell and do have a date utility that has a -d option, you could comment out the printf command in that loop and uncomment the date command.
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Get all business days from week including today
abhii
I am trying to get last 5 business day . trying for d in Mon Tue Wed Thu Fri do date +%Y%m%d -d "last $d" done gives me date Thu Oct 20 23:56:26 EDT 2016 20161017 20161018 20161019 20161013 20161014 expected output should be 20161017 20161018 20161019 20161020... How to Post in the The UNIX and Linux Forums
1
How to Post in the The UNIX and Linux Forums
UNIX date fuction - how to deduct days from today's date
juzz4fun
Hi, One of my Unix scripts needs to look for files coming in on Fridays. This script runs on Mondays. $date +"%y%m%d" will give me today's date. How can I get previous Friday's date.. can I do "today's date minus 3 days" to get Friday's date? If not, then any other way?? Name of the files is...... Shell Programming and Scripting
4
Shell Programming and Scripting
[Solved] Replace yesterday date with today's date except from the first line
Lilu_CK
Hello, I have a file like this: 2012112920121130 12345620121130msABowwiqiq 34477420121129amABamauee e7748420121130ehABeheheei in case the content of the file has the date of yesterday within the lines containing pattern AB this should be replaced by the current date. But if I use...... Shell Programming and Scripting
3
Shell Programming and Scripting
Shell Scripts - shows today’s date and time in a better format than ‘date’ (Uses positional paramete
citizencro
Hello, I am trying to show today’s date and time in a better format than ‘date’ (Using positional parameters). I found a command mktime and am wondering if this is the best command to use or will this also show me the time elapse since 1/30/70? Any help would be greatly appreciated, Thanks...... UNIX for Dummies Questions & Answers
3
UNIX for Dummies Questions & Answers
Calculate 30/31 days from today date script
coolgoose85
Hi Guys, I was working some time ago n was in need to calculate date 30/31 days from today including Feb (Leap yr stuff). Today date is variable depending on day of execution of script. I tried searching but was not able to get exactly what I needed....So at that I time I implemented by my own...... Shell Programming and Scripting
3
Shell Programming and Scripting

Featured Tech Videos