Linux for new users part 5 – dates
Continuing my series for those new to running Moodle on a linux server.
By now it should be second nature for you to open a terminal using Ctrl+Alt+T. We will continue exploring the date command.
First of all, try adding these different options one by one, and see if you can anticipate what each might be doing:
- %a prints the name of the day, abbreviated to Mon, Tue, Wed, etc.
- %A Prints the full name of the day, Monday, Tuesday, Wednesday, etc.
- %u prints the number of the day of the week, where Monday=1, Tuesday=2, Wednesday=3, etc.
- %w prints the number of the day of the week, where Sunday=0, Monday=1, Tuesday=2, etc.
- %d prints the day of the month, with a leading zero (01, 02 … 09) if required.
- %e prints the day of the month, with a leading space (‘ 1’, ‘ 2’ … ‘ 9’) if required. Note that the apostrophes do not print.
- %j prints the day of the year, with up to two leading zeroes, if required.
One important reminder above you should have recognised … %a and %A are different, and do different things. This is simple and instant example of why you need to always remember linux commands are case sensitive – and here you can see %a and %A produce different results.
Let’s try some commands that work with the week of the date:
Similar to working with the day of the week, it is possible to work wth the months:
- %U prints the week number of year, considering Sunday as the first day of the week. For example, the third week of the year, twentieth week of the year, etc.
- %V prints the ISO week number of the year, considering Monday as the first day of the week.
- %W prints the week number of the year, considering Monday as the first day of the week.
As you might expect, there are options to display the month in various ways too, try these:
%b or %h
- %b or %h prints the name of the month abbreviated to Jan, Feb, Mar, etc.
- %B prints the full name of the month, January, February, March, etc.
- %m prints the number of the month, with a leading zero if required 01, 02, 03 … 12.
There’s an interesting point here. Note that the first option illustrates how you can use %b or %h to do exactly the same thing. As you begin to use the Terminal you will find some commands do this, presenting alternatives. It really doesn’t matter which you use.
Finally this month, let’s look at how to control the display of the year.
- %C prints the century without the year. In 2019 it will print 20.
- %y prints the year as two digits. in 2019 it will print 19.
- %Y prints the year as four digits.
This is another good example of why you need to know that the command line and linux commands are case sensitive – look at the “y” and the “Y” create different output.
More learning about the Terminal or CLI next month !
- Moodle 4.0 – 15th May 2022
- Moodle 4.0 other highlights – 14th May 2022
- Moodle 4.0 Accessibility – 9th May 2022