date command in linux allows you to display date and time in your linux terminal. You can also change the date and time by using some flags.
date command in linux with flags | examples
![]() |
date command in linux with flags |
Hello guys, In this session, you will see how you can use the "date" command in Linux.
The "date" command is used to display or change the value of system time and date information.
date command
![]() |
simple date command |
$date
The "date" command is simple you can just write "date" and press ENTER.
It's going to "display" you the current date and time.
Change date and time using [-s] flag
![]() |
date command with -s flag |
$date -s [date] [time]
If you want to change the date and time then you have to use "-s" flag with the "date" command.
You can just say date -s "08/03/2020 05:34:00" press ENTER.
After this "-s" whatever date and time you will set inside a string it will be set as a system time.
Formatting Date and Time using flags
Flags which you can use with this "date" command to format the date and time.
Format | Output |
---|---|
+%m | Show the months in numerical format |
+%h | Show the months in character form (Jan-Dec) |
+%B | Show the months in character form (January-December) |
+%d | To print the day of the month |
+%y | To show the current year |
+%T | Show time as (hh:mm:ss) |
+%H,+%M and +%S | prints Hour, Minutes and Seconds |
+%D | To Display Date, Month and Year (dd/mm/yy) |
![]() |
Formatting date and time using various flags |
$date flag
You can also use single quotes (') or double quotes (") with these flags.
Another way to print Date and Time
![]() |
Example |
$date "+DATE: %d-%m-%y%n TIME %H:%M:%S"
So in this way you can use the "date" command in Linux.
Conclusion
To know more about the "date" command just go through this man page and see how you can use this "date" command because it's a vast command.
So just read this man page whenever you want to write.
I hope you have enjoyed this tutorial, Thank You.
HAVE A NICE DAY💓
Related,