🔹Exploring date command🔹

M G GOVARDHAN GOWDA
5 min readSep 27, 2021

Task Description 📄

📌 Explore date command and with options and try to use every option and create a simple document for it.

The Linux date command is used to display the system date and time. We can also print the past date, future date, or set the date manually. By default, the date command prints the current date of the Linux system.

How to check whether the date command is installed or not?

date --version

Syntax:

date [OPTION]... [+FORMAT]
date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]

Options with Examples

1: date (no option): With no options, the date command displays the current date and time, including the abbreviated day name, abbreviated month name, day of the month, the time separated by colons, the time zone name, and the year.

Command: 
$date
Output:
Fri Sept 24 19:17:40 IST 2021

2. date (date=” mm/dd/yy”): This option lets us display the date and time in any format. This would not affect the system’s date and time. It will remain the same.

date --date="09/24/2021"

3. date (date=yesterday): This option lets us display the date and time of yesterday.

date --date=yesterday

4. date (date=1year): This option lets us display the date and time of the same day but one year after.

date --date=1year

5. date (date=”1 year ago”): This option lets us display the date and time of the same day but one year ago.

date --date="1 year ago"

6. date +%a = This option lets us display the current abbreviated weekday name. date +%A = This option lets us display the current full weekday name.

7. date +%b = This option lets us display the current abbreviated month name. date +%B = This option lets us display the current full month name.

8. date +%c = This option lets us display the local date and time. date +%C = This option lets us display the current century name.

9. date +%d = This option lets us display the day of the month. date +%D = This option lets us display the current date with (mm/dd/yy) format.

10. date +%e = This option lets us display the day of the month. date +%F = This option lets us display the current date with (yy-mm-dd) format.

11. date +%g = This option lets us display the last two digits of the year. date +%G = This option lets us display the current year.

date +%a
date +%A
date +%b
date +%B
date +%c
date +%C
date +%d
date +%D
date +%e
date +%F
date +%g
date +%G

12. date +%h = This option lets us display the abbreviated month name. date +%H = This option lets us display the hour of the day.

13. date +%I = This option lets us display the hour. date +%j = This option lets us display the day of the year.

14. date +%k = This option lets us display the hour. date +%l = This option lets us display the hour.

15. date +%m = This option lets us display the month of the year. date +%M = This option lets us display the minute of the day.

date +%G
date +%h
date +%H
date +%I
date +%j
date +%k
date +%l
date +%m
date +%M
date +%n

16. date +%n = This option lets us display the new line. date +%N = This option lets us display the nanoseconds.

17. date +%p = This option lets us display AM/PM. date +%P = This option lets us display am/pm.

18. date +%q = This option lets us display the quarter of the year. date +%R = This option lets us display hours:minutes in 24 hrs format.

19. date +%r = This option lets us display the current time in 12 hr format. date +%s = This option lets us display the second's science 1978–01–01 00:00:00 UTC.

20. date +%S = This option lets us display the seconds. date +%t = This option lets us display a tab.

date +%M
date +%n
date +%N
date +%p
date +%P

date +%q
date +%R
date +%r
date +%s
date +%S
date +%t

Date command with zenity

21. This option lets us display the date on the output pop-up of the zenity info command.

zenity --info --title "ARTH_2.0" --text "Todays date is $(date +%x)"

Output:-

22. Here is a quick video of the Zenity entry command and different date commands

You can Connect me on:-

https://www.linkedin.com/in/mggovardhan-gowda-4444aa1a0/

THANKS FOR READING….

--

--

M G GOVARDHAN GOWDA

MLOPS internship trainee @LinuxWorld informatics Pvt. LTD. || Student @Dayananda Sagar University |