Setting date/time on UNIX

Tuesday, February 20, 2007

There are rare times that I need to update the time on some UNIX servers. If the NTP service is setup and running properly, I shouldn’t have to worry about this.

I found one of my database servers was about 5 minutes behind the correct time. I wanted to correct the time manually and I’m always forgetting the format. I can find the information using ‘man date‘ at the command prompt and reviewing the examples. However, writing about it will hopefully infuse the format in my brain and provide a quick reference in the future.

The syntax goes something like this:

date mmddhhmi

where mm = month
dd = day of month
hh = hour
mi = minute

Changing the date/time requires root access. In my case, root access is attainable using sudo.

sudo date 02201015

The command above sets the date/time to February 20, 2007 10:15am. As mentioned in the man pages, the current year is the default because no year is supplied in the setting.