Setting date/time on UNIX

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.


13 Responses to Setting date/time on UNIX

  1. Ewan says:

    If ntp is installed but not configured, you can also run ntpdate -s servername which will contact the ntp server specified and set your time exactly, like ntpd itself would do

  2. I have a general question regarding changing the date on database server.

    In order to do some testing for daylight saving time patch, some of our people decided to change the date/time on the Linux database server running a 10.2 single instance database. They kept changing dates back and forth several times. Finally, when the dust settled, ‘ls -ltr’ showed files modified on February 11, 2007 at the end – after March 11, 2007 files.

    My question is what’s the effect of this dynamic date/time change on Oracle database? What happens to those DBMS_SCHEDULER jobs? What about internal Oracle dependency on SYSDATE,SYSTIMESTAMP etc.? Is this unhealthy to a running database? If so, then what’s the proper way of changing the date/time on a server? Shutdown the database, change the date and then restart the database?

    Now what about a RAC database? Someone changes the date on one server and doesn’t on the other. Is the database going to crash?

  3. nour says:


    many thanks for your useful brief,

    my question

    how can i change year time from 2006 to 2007??
    is that possible or not?

    best regards

  4. mrothouse says:

    You can specify the year using the command below. For example, March 26, 2007 10:50am would be specified as shown below. The century/year goes at the end after the date and time.

    date 032610502007

    This information can be found in the man pages as well. Hope this helps.


  5. charles K says:

    in IBM server risc server 6000, i set time in root user.
    the command is

    “date 02201015”

    the date set , but after restart the date is goes to 1970.

    Please say permananat command to set date in unix.

    Thank U

  6. mrothouse says:

    As mentioned in a previous comment, you can specify the year using the command below. The century/year goes at the end after the date and time. For example, March 27, 2008 10:50am would be specified as shown below.

    date 032710502008

    This works on HP-UX and Solaris. I have no AIX platform to test this on, but would imagine the information I provided can also be found in the man pages. Hope this helps.


  7. Rahul says:

    I am writing a shell script which asks the user to enter the directory path(e.g x/y/z) and then I am trying to substitute the entered path with an existing path in file using “sed” command.But thats not working.It says – “sed: command garbled:”.I feel Backslashes are causing problems.

    Please help.

  8. venkat says:

    Hi ,

    I want to change the date format as below..


    i want to change it to 20110512

    how can i do this…

  9. mrothouse says:

    According to the man pages, it would be something like this:

    date +%Y%m%d

    Also found these through Google searching on “date format in unix”:

  10. Mekerira says:

    Hi Mike,

    I’m very new to unix
    I have a checked project , there exists a file called xxx.config .
    now my task is to find all the files in the checked out project which references to this xxx.config file.
    how do i use grep or find command .

  11. E.Umar says:

    Question on changing date and time,

    We use Putty to access company servers.

    The time in Server screen shows the correct local New Zealand time. (exm:13:00)

    But the Butty shows GMT time which is 12 hours behind Nwe Zealand Local time (GMT01:00). if I use Date command in Putty to Change the time, it is going to modify the time in Server according to GMT standard and making it 12 hours early than local New Zealand time.

    Is there any way we can configure Putty to pick up New Zealand Standard Time, instead of GMT?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: