How do I view and set date under UNIX operating systems?
The date command under UNIX display date. It is also used to set date and time. You must be the super-user (root) to change the date and time.
UNIX Date Command Syntax
date date "+format"
Task: Display Current Date and Time
Type the following command:
dateSample outputs:
Tue Oct 27 15:35:08 CDT 2009
Task: Set The Current Time
To set the current time to 05:30:30, enter:
date 0530.30
Task: Set Date
Set the date to Oct 25, 12:45 a.m., enter:
date 10250045
Another example - set the current date and time to Oct 15, 2009 04:30 you type:
date --set="20091015 04:30"
Task: Generating Output
WARNING! These examples may not work on Linux computer i.e. GNU coreutiles date command. All examples are tested on HP-UX, AIX, Sun Solaris and other propitiatory UNIX operating systems only.Type the following command:
date '+DATE: %m/%d/%y%nTIME:%H:%M:%S'
Sample outputs:
DATE: 10/27/09 TIME:15:50:44
Try the following examples:
date "+%m/%d/%y" date "+%Y%m%d" date +'%-4.4h %2.1d %H:%M'
Unix Command Help
Type the following command to read the date command man page:
man date
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- My 10 UNIX Command Line Mistakes
- Linux: 20 Iptables Examples For New SysAdmins

- 25 PHP Security Best Practices For Sys Admins
- The Novice Guide To Buying A Linux Laptop
- 10 Greatest Open Source Software Of 2009
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Linux Video Editor Software
Facebook it - Tweet it - Print it -


{ 9 comments… read them below or add one }
@Vivek – Do you confirm this one ? My date ((GNU coreutils) 6.10) does not like it much.
date +'%-4.4h %2.1d %H:%M'
What does it do on your system?
@Philippe,
I think I used that one on proprietary AIX or may be on HP-UX UNIX box. The month field is four characters long, left side. Same goes for the day (2 chars long). It will not work on *GNU coreutils*. You can try them on HP-UX or AIX and should provide output as follows:
@Vivek: Then, would you consider adding some warning/advice/comment to prevent your readers loosing time (and hairs ;-) ).
Title does says “UNIX Date Command Examples” and Linux != UNIX. Nevertheless, your suggestion is accepted :). Thanks!
very nice contain in this site……….useful very much in study…………..
will date –version work in linux? why is the output different that echo “–version” | date
Hi Learner,
Right way to give parameters on command line is:
date –version
When you want a program to use some input from a pipe is:
echo “some text used as input” | tr “[[:lower:]]” “[[:upper:]]”
But these are two really different functionalities. They are not equivalent at all, so they cannot yield the same.
– Philippe
Consider – echo “–version” | date
here echo “–version” will give the output –version , which will act as an input to date. .
so we should get date –version.
But we do not get the same output from echo “–version” | date
and date –version. Can you please explain why the output is different.
You confuse [standard input usage] with [parameters on the command line] which are different kind of inputs, which cannot be exchanged.
The genuine way to give parameters to a command is to give them on the program call, which is made on the command line.
There a other ways to achieve parameter passing to a command, such as using a specific file, or using environment variables.
On the other hand, standard input is commonly used to give _data_ to process, not parameters.
As a matter of facts, [date] command does make any use of standard input.
So you can pipe _anything_ you want, [date] won’t ever use it. You might have pipe (with echo) any text, [date] won’t use it.
Make sure by Reading The Fantastic Manual,
by issuing the command: man date
Do you think you get the point?