Linux Set Date and Time From a Command Prompt

by Vivek Gite on October 2, 2006 · 80 comments

How can I set the system date and time from the command prompt (bash shell)? I don't have GUI installed and I am login over ssh session. How can I set date under Linux operating systems?

Use the date command to display the current date and time or set the system date / time over ssh session. You can also run the date command from X terminal as root user.

This is useful if the Linux server time and/or date is wrong, and you need to set it to new values from the shell prompt.

You must login as root user to use date command.

Linux Set Date

Use the following syntax to set new data and time:
date --set="STRING"

For example, set new data to 2 Oct 2006 18:00:00, type the following command as root user:
# date -s "2 OCT 2006 18:00:00"
OR
# date --set="2 OCT 2006 18:00:00"

You can also simplify format using following syntax:
# date +%Y%m%d -s "20081128"

Linux Set Time

To set time use the following syntax:
# date +%T -s "10:13:13"
Where,

  • 10: Hour (hh)
  • 13: Minute (mm)
  • 13: Second (ss)

Use %p locale’s equivalent of either AM or PM, enter:
# date +%T%p -s "6:10:30AM"
# date +%T%p -s "12:10:30PM"

See also:

  • You can also set new timzone using this mini-howto.

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

{ 80 comments… read them below or add one }

1 Johan Dalevi April 8, 2007

Found out i had to set the date like this:
# date -s 2007.04.08-22:46+0000

Reply

2 PRADEEP December 20, 2010

date -s “2 OCT 2006 18:00:00″

Reply

3 mani December 12, 2007

How can I set the proxy setting from the command prompt (bash shell)?

Reply

4 raju January 10, 2008

Just This code is ultimate.It is simple and worth full.Thank you very much providing help to people.

Reply

5 kiran March 8, 2008

It Work’s Thanks a Lot,

Kiran.

Reply

6 varun September 8, 2010

thank

Reply

7 djeikyb May 21, 2008

mani– run:
export http_proxy=’http://10.10.1.2:3128′

Reply

8 R.K.Majhi June 24, 2008

It helped me to change the server timings without any difficulty. I tried to get help from the command prompt but it didn’t render anything. Thanks for the solution.

Reply

9 Mohit Guleria June 27, 2008

Do check and sync hardware clock with:
# hwclock –show
# hwclock –systohc

Reply

10 Paolo July 24, 2008

This configuration string is exactly what i’m searching for. thanks.

Reply

11 job wakhungu July 30, 2008

i had to set the date by using {date -s “wed jul 30 19:41:00 BST 2008″} while at the root.

Reply

12 gujubhai August 13, 2008

hey thanks a million,
this worked right the first time…

was wondering how to do it untill i found ur site…

keep up the good work…very neat for freshers to *nix

cheers

Reply

13 rostiarso August 21, 2008

You could also simplify the format of input date as example below
date +%Y%m%d -s "20080817" (set new date to August 17, 2008) without typing full date format

Reply

14 Abdussami October 26, 2008

Just amazing command… & help.. gr88 work.. keep it up.

May allah bless you…

Reply

15 marius October 27, 2008

thank you!!!!

i have fedora 9 i can not change the time using his time control application. he ask for my root password, and then he says that it is not correct…. crazy program :)

the man page of date did not showed me any example, i what i tried was not accepted.

thank you.

Reply

16 D November 2, 2008

Thanks

Reply

17 pramod November 7, 2008

this is gr8
I synced HW clk with sysstem clock also.
But after reboot the time is again changed

Reply

18 Frank Haynes November 27, 2008

The man page for the ‘date’ command is WORTHLESS.

Now that I read here how to format the input string in order to set the clock my life is good. THANK YOU!

Reply

19 saiph savage November 28, 2008

thanks !
very nice article, super easy :)

Reply

20 Venu Reddy December 18, 2008

Thanks brother,
It has worked. Great work…!

Reply

21 Neelesh December 22, 2008

date set=”2 OCT 2006 18:00:00″

it is doesn’t work.
I have to change my linux system time./ Right now it is shows correct time on my machine but when i open my gmail account it’s shows wrong time of my emails.Due to it’s system time.

Any idea?

Reply

22 Dennis Quek January 21, 2009

Anyone has ideas how to set Dates 1 day or 2 dates ago. What about setting it +2 hours in advance etc ?

Reply

23 Nickalf February 11, 2009

Hi All,

The problem I’m having is, the time/date changes at the time I do it, but doesn’t hold after a reboot – how can i lock it into the Server’s clock..

Neelesh – Try date -s ”2 OCT 2006 18:00:00″ instead

Nickalf. . .

Reply

24 Adnan February 17, 2009

Thanx alot.. working properly

Reply

25 Bimlesh sharma February 24, 2009

date -s ”2 OCT 2006 18:00:00″ is set for the time being. Need o set CMOS clock using “hwclock” command. That will be right solution.

Reply

26 C Chavez March 3, 2009

SIDE NOTE RE: SETTING HWCLOCK

format should be:

# hwclock –systohc

(note double -)

CHeers!

Reply

27 George March 18, 2009

Thanks alot

THis has worked like yesterday

Keep up the good work.

Regards,

George Ndung’u
IT & Logistics Manager
LSHS

Reply

28 Ajay Shaldiwal March 20, 2009

Dear Sir,

Thanks a Lot.

Ajay

Reply

29 Mister D May 5, 2009

Thanks!!!

Reply

30 Gopal May 5, 2009

One more thank you for your simple explanation and great example. I couldn’t figure out the format from reading the date man page.

Reply

31 Zahid May 14, 2009

Nice

Reply

32 cat June 1, 2009

Thank you so much, it works.

Reply

33 en June 13, 2009

Thank you! This information was very helpful.

Some of the examples you have presented here would be hard to derive from the date man page.

Reply

34 Alan July 25, 2009

I’ve just got a Datawind Ubisurfer and to set the date/time I had to type:
# date 07252208002009
25 July 2009 time 20:08

decodes as # date MMDDhhmmssYYYY

month day hour minutes seconds year
Thanks for other scripts they sent me in the right direction.
(This does come up as UTC whatever that is!)

Reply

35 herMz August 10, 2009

this is awesome.. thnks a lot..

Reply

36 Srini August 18, 2009

Thanks…:)

Reply

37 FAHIM August 28, 2009

Thanks its works….!!!

Reply

38 Dattatray Naik September 5, 2009

Thanks It Works.

Reply

39 vignesh September 6, 2009

Thanks for giving the command.. It’s very helpful for me.

Reply

40 Murugesh September 8, 2009

info date Examples

Reply

41 thomas September 16, 2009

I am a layman in linux, but this sure helped me change my server time remotely.thankyou.

Reply

42 Kent September 25, 2009

Thanks C Chavez. I had a real time trying to get the hwclock to stop resetting. One line and BAM! Thanks again!

Reply

43 seth October 1, 2009

THIS COMMAND DOESN’T WORK FOR OPEN BSD TO CHANGE THE DATE AND TIME

Reply

44 bharanitharan October 5, 2009

Thanks Man :) it have worked for me ;-)

Reply

45 vinodanctk@gmail.com October 29, 2009

Dear sir,
Many Thanks for the help
Thanks

Reply

46 Mario Chamorro November 4, 2009

Thank you , Murugesh . This is the first time I have ever found those ‘Info’ pages useful . I need this for a SQL script at work that needs to fetch data from 7 days ago . Murugesh to the rescue!

[ ~ ] date –date=’7 days ago’
Wed Oct 28 20:39:35 GMT 2009
[ ~ ]

– Mario

Reply

47 Jaxon November 9, 2009

It works, I have to check any time changing after restart the PC

Reply

48 sin December 9, 2009

thanks it worked in first time… Really Thanks

Reply

49 Sana December 22, 2009

Thanks a lot for your help

Reply

50 nenopera January 18, 2010

$ sudo date +%Y%m%d%T -s “20081225 10:05:00″

[sudo] password for nenopera:
2008122510:05:00

$ date

Thu Dec 25 10:05:02 EST 2008

Reply

51 sumer February 8, 2010

`date +%G%m%d`-acb.txt
this is my current date format. I wants to set last day’s date instead of current. I try this from last week . Plz help me…………

Reply

52 shabbirali March 3, 2010

Date command is sweet and simple… :)
Man page is man!!!

Reply

53 sumer March 3, 2010

thanks guys….lov u ……..

Reply

54 ratish singh March 15, 2010

How can i change my system date format on linux os?

Reply

55 vishal April 9, 2010

satish,

follow the steps
1.check date with date command
2.set date with date -s command
3.hwclock –systohc
4.hwclock –show

Vishal

Reply

56 sunraj June 9, 2010

i like your commands. i am realy very impress

Reply

57 Indika April 23, 2010

Hi this is really helpful guys….. thanks alot.

Reply

58 the birdie April 29, 2010

Thanks for passing on your knowledge.

Reply

59 luciano May 13, 2010

# date set=”2 OCT 2006 18:00:00″ wrong!!!!
# date –set=”2 OCT 2006 18:00:00″

Reply

60 gayan June 11, 2010

thinks bro,

Reply

61 Vikas YAdav June 26, 2010

It was amazing……!!!!!!!!!

Reply

62 praV July 9, 2010

THANKS

Reply

63 P.K.Ghosh July 29, 2010

Thank yo very much for sharing your knowledge
It’ really works fine
So… bye

Reply

64 kiran October 25, 2010

Thank you very much for giving me suggestion it is very usefull for me.

regards,
kiran ugale.

Reply

65 vijay November 9, 2010

Thanks a lot guys.. Everything worked.

Reply

66 William Simbota November 11, 2010

I really appreciate. I think I will learn Linux at a fast pace with your assistance.

Reply

67 Naresh Babu December 21, 2010

Information about date was very much helped me
Thanks

Reply

68 seachen January 13, 2011

my vps time currently is as below:

[root@server25 ~]# date
Thu Jan 13 17:22:54 UTC 2011

how to change it to Thu Jan 14 01:25:54 MYT 2011

Reply

69 iskandar January 27, 2011

hai…
im have a problem about time on fedora
im use tht comman date, its change but if i restart my fedora is time will change
and wrong time after restart the komputer..
can help me?

Reply

70 iskandar January 27, 2011

now i understand how tht comman
tq friend..
now my fedora time is ok
the time is ok not change anymore..
Tq

Reply

71 micxz March 18, 2011

not a big deal but small typo:
# 30: Second (ss)
should read 13 or in the example it should be :30

Reply

72 ankit maini March 22, 2011

thanx :)

Reply

73 Mohit G April 11, 2011

View:
hwclock –show
date
ls -l /etc/localtime

Change:
To change the time use date followed by the month, day, hour, minute, and year all numeric and no spaces.
date 041106232011
hwclock –systohc
ln -sf /usr/share/zoneinfo/ /etc/localtime
vi /etc/sysconfig/clock (update timezone if redhat)
service ntpd restart

Check:
hwclock –show
date
ls -l /etc/localtime

Reply

74 mz May 24, 2011

it worked fine.
MZ

Reply

75 Jaat June 25, 2011

How to change duplex setting of lan card in Rhel5

Reply

76 sasi July 30, 2011

thankz

Reply

77 Erik Martis August 16, 2011

Hi there,

thank you very much for the info …. works like a charm !!!
btw, once I set my system date and time correctly the use of the
“#hwclock –systohc” command rules ´em all too !!!

saludos!
eriku

Reply

78 prince f November 14, 2011

thank you!

Reply

79 Soni Peterson December 23, 2011

To me, setting date and time in linux was really difficult and I was searching many documents / websites for this, and thank you very much for such comprehensive information for setting date and time. It helps me a lot.

Reply

80 surendra February 6, 2012

Thanks

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">




Previous post:

Next post: