HowTo: UNIX Set Date and Time Command

I recently noticed that one of my UNIX servers was about 4 hours behind the correct time. I wanted to correct the date and time manually. How do I set date and/or time under UNIX operating systems using command line options?

The date command displays the current day, date, time, and year as well as it can set both the date and time for you. To see the current date and time, enter:
$ date
You must be login as root to set / change date under UNIX. The syntax to set date and time under UNIX and UNIX like operating system is as follows:

date MMddhhmm[[cc]yy]


  • MM : Month (two-digit numeric month)
  • dd : Day (two-digit numeric day i.e. day of month)
  • hh : Hour
  • mm : Minutes (30)
  • cc : First two digits of the year (10)
  • yy : Last two digits of the year (2010).

To set date to April 27, 2010 8:00am under HP-UX, AIX, Sun Solaris or UNIX like operating system, enter:

date 042708002010

HP-UX UNIX Set Date Example Using Various Formats

Using the mmddHHMM[[cc]yy][.ss] format, set date:

date 010709342000
date 0107093400.00
date 010709342000.00

Using the [[cc]yy]mmddHHMM[.ss] format:

date 0001070934
date 200001070934
date 200001070934.00

Using the mmddHHMM[.ss[[cc]yy]] format:

date 01070934.0000
date 01070934.002000


To set the date and time under AIX UNIX, enter:

date 0217185010

The above sets the date and time to Wed Feb 17 18:50:00 CST 2010.

Getting Help About date Command

You can also view the manual page on date using the following command:
$ man date

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 6 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
6 comments… add one
  • bloodywing Apr 30, 2011 @ 0:43

    Another nice way is to use a ntp-client, once you set the time almost correct, launch the ntp and you get the “real” correct local time.

    • Superman May 5, 2011 @ 19:04

      What are you talking about bloodywing? I think you completely overshot on this questions.
      date -s “11/20/2003 12:48:00”
      date ‘+DATE: %m/%d/%y%nTIME:%H:%M:%S’ – Would list the time and date in the below format:

      DATE: 02/08/01

      • sugartest Mar 23, 2016 @ 17:19

        Superman didn’t get it xD, SuperDarn ! +1 bloodywing, it is often recommended to sync time from NETWORK TIME PROTOCOL servers to be able to get A REAL date and time based on atomic clocks worldwide !

  • joec May 9, 2011 @ 20:10

    can you use the ‘epoch’ time as a way to set the date? i.e if I have two servers and compare the date-stamp using date +%s, can I check the difference between the two and update the one server with respect to the other? In other words: %date ‘someintegervalue+x’?


  • rajesh Dec 26, 2012 @ 11:54

    How can i view 5days before date on hp-ux.
    please can anybody help me?


    • debendra nath panigrahi Feb 13, 2014 @ 12:44

      we can use this cmd to view 5days before date on hp-ux.

      date -d ‘5 days ago’

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum