I'm trying to get the current date of my school server (I don't have root access) to complete this task:

Write a script that will countdown to Friday(example: output would be "Today is Sunday, you have 5 days until Friday"). You should use the time and day from the server, not the user.

closed as unclear what you're asking by DarkHeart, Anthon, Rui F Ribeiro, G-Man, dr01 May 1 '17 at 6:48

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Have you encountered the date command? – Fox Apr 30 '17 at 22:21
  • What have you tried? What is not working? unix.stackexchange.com/help/how-to-ask – Patrick Apr 30 '17 at 22:32
  • date command shows the computer date and time, is that correct? I've tried ntpdate, rsh <host name> date, uptime – NSR Apr 30 '17 at 22:40
  • Type man date. Read the output. – G-Man May 1 '17 at 6:34

Since you tagged Linux, you have a powerful date utility at your disposal. Here's how I might approach such a task (depending on what you want to have happen if today is Friday -- this will take you into the next week):

now=$(date +%s)
fri=$(date +%s -d "next Friday")
days=$(( (fri - now) / 86400))
echo Today is $(date +%A), you have $days until Friday

Here's a start:

date "+Today is %A"

date "+The current day of the week as an integer is %u"

Have a look at the manual for the date command.


Using dateutils to print today's date:

$ dateconv -f "Anno Domini %OY %Om %Od" now

Not the answer you're looking for? Browse other questions tagged or ask your own question.