Linux Set Date and Time From a Command Prompt

by on October 2, 2006 · 121 comments· LAST UPDATED March 18, 2011

in , ,

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.
TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 121 comments… read them below or add one }

1 Johan Dalevi April 8, 2007 at 8:51 pm

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

Reply

2 PRADEEP December 20, 2010 at 3:19 am

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

Reply

3 mani December 12, 2007 at 6:57 am

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

Reply

4 raju January 10, 2008 at 7:25 am

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 at 4:26 am

It Work’s Thanks a Lot,

Kiran.

Reply

6 varun September 8, 2010 at 12:26 pm

thank

Reply

7 djeikyb May 21, 2008 at 12:18 am

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

Reply

8 R.K.Majhi June 24, 2008 at 1:29 pm

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 at 5:08 pm

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

Reply

10 Maurice March 6, 2013 at 6:38 am

This is actually an important one!! Many thanks!

Reply

11 Paolo July 24, 2008 at 12:16 pm

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

Reply

12 job wakhungu July 30, 2008 at 4:49 pm

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

Reply

13 gujubhai August 13, 2008 at 9:43 am

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

14 rostiarso August 21, 2008 at 3:41 am

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

15 Abdussami October 26, 2008 at 11:35 am

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

May allah bless you…

Reply

16 marius October 27, 2008 at 7:07 pm

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

17 D November 2, 2008 at 10:09 am

Thanks

Reply

18 pramod November 7, 2008 at 4:11 am

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

Reply

19 Frank Haynes November 27, 2008 at 6:35 pm

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

20 saiph savage November 28, 2008 at 3:22 pm

thanks !
very nice article, super easy :)

Reply

21 Venu Reddy December 18, 2008 at 6:35 am

Thanks brother,
It has worked. Great work…!

Reply

22 Neelesh December 22, 2008 at 2:04 pm

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

23 Dennis Quek January 21, 2009 at 5:10 am

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

Reply

24 Nickalf February 11, 2009 at 7:49 pm

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

25 Aman September 2, 2011 at 5:58 am

date –set=”2 sep 2011 11:27:20″

Reply

26 zia March 6, 2012 at 3:02 am

date -s ”2 OCT 2006 18:00:00″ Thanks it worked nicely oh! thanks

Reply

27 Adnan February 17, 2009 at 9:01 am

Thanx alot.. working properly

Reply

28 Bimlesh sharma February 24, 2009 at 11:28 am

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

29 C Chavez March 3, 2009 at 9:41 pm

SIDE NOTE RE: SETTING HWCLOCK

format should be:

# hwclock –systohc

(note double -)

CHeers!

Reply

30 George March 18, 2009 at 5:57 am

Thanks alot

THis has worked like yesterday

Keep up the good work.

Regards,

George Ndung’u
IT & Logistics Manager
LSHS

Reply

31 Ajay Shaldiwal March 20, 2009 at 6:30 am

Dear Sir,

Thanks a Lot.

Ajay

Reply

32 Mister D May 5, 2009 at 9:17 am

Thanks!!!

Reply

33 Gopal May 5, 2009 at 5:59 pm

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

34 Zahid May 14, 2009 at 12:26 pm

Nice

Reply

35 cat June 1, 2009 at 12:12 pm

Thank you so much, it works.

Reply

36 en June 13, 2009 at 9:14 am

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

37 Alan July 25, 2009 at 9:20 pm

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

38 herMz August 10, 2009 at 9:33 am

this is awesome.. thnks a lot..

Reply

39 Srini August 18, 2009 at 2:01 pm

Thanks…:)

Reply

40 FAHIM August 28, 2009 at 3:48 pm

Thanks its works….!!!

Reply

41 Dattatray Naik September 5, 2009 at 7:42 am

Thanks It Works.

Reply

42 vignesh September 6, 2009 at 7:03 am

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

Reply

43 Murugesh September 8, 2009 at 5:33 pm

info date Examples

Reply

44 thomas September 16, 2009 at 11:12 am

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

Reply

45 Kent September 25, 2009 at 9:03 am

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

Reply

46 seth October 1, 2009 at 2:18 pm

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

Reply

47 bharanitharan October 5, 2009 at 11:16 pm

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

Reply

48 vinodanctk@gmail.com October 29, 2009 at 8:23 am

Dear sir,
Many Thanks for the help
Thanks

Reply

49 Mario Chamorro November 4, 2009 at 8:43 pm

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

50 Jaxon November 9, 2009 at 8:35 am

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

Reply

51 sin December 9, 2009 at 6:31 pm

thanks it worked in first time… Really Thanks

Reply

52 Sana December 22, 2009 at 4:43 am

Thanks a lot for your help

Reply

53 nenopera January 18, 2010 at 9:11 am

$ 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

54 sumer February 8, 2010 at 7:19 am

`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

55 shabbirali March 3, 2010 at 8:07 am

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

Reply

56 sumer March 3, 2010 at 10:21 am

thanks guys….lov u ……..

Reply

57 ratish singh March 15, 2010 at 1:41 pm

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

Reply

58 vishal April 9, 2010 at 8:28 am

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

59 sunraj June 9, 2010 at 1:28 pm

i like your commands. i am realy very impress

Reply

60 Indika April 23, 2010 at 5:09 pm

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

Reply

61 the birdie April 29, 2010 at 11:20 am

Thanks for passing on your knowledge.

Reply

62 luciano May 13, 2010 at 3:22 pm

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

Reply

63 gayan June 11, 2010 at 3:45 am

thinks bro,

Reply

64 Vikas YAdav June 26, 2010 at 8:36 am

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

Reply

65 praV July 9, 2010 at 4:47 pm

THANKS

Reply

66 P.K.Ghosh July 29, 2010 at 6:57 am

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

Reply

67 kiran October 25, 2010 at 9:19 am

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

regards,
kiran ugale.

Reply

68 vijay November 9, 2010 at 4:28 am

Thanks a lot guys.. Everything worked.

Reply

69 William Simbota November 11, 2010 at 12:46 pm

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

Reply

70 Naresh Babu December 21, 2010 at 12:26 pm

Information about date was very much helped me
Thanks

Reply

71 seachen January 13, 2011 at 5:36 pm

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

72 iskandar January 27, 2011 at 6:45 am

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

73 iskandar January 27, 2011 at 7:40 am

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

Reply

74 micxz March 18, 2011 at 3:34 pm

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

Reply

75 ankit maini March 22, 2011 at 1:13 pm

thanx :)

Reply

76 dani March 25, 2011 at 6:37 am

hello i want to change date separator… from / to .(dot) can u help me?
for example 23/03/2011 to 23.03.2011

Reply

77 Mohit G April 11, 2011 at 1:38 pm

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

78 mz May 24, 2011 at 9:41 am

it worked fine.
MZ

Reply

79 Jaat June 25, 2011 at 11:07 am

How to change duplex setting of lan card in Rhel5

Reply

80 Brent November 30, 2012 at 10:54 pm

On the same subject, how do I make non-dairy chocolate chip cookies?

Reply

81 sasi July 30, 2011 at 11:27 am

thankz

Reply

82 Erik Martis August 16, 2011 at 6:27 pm

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

83 prince f November 14, 2011 at 6:37 pm

thank you!

Reply

84 Soni Peterson December 23, 2011 at 3:49 am

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

85 surendra February 6, 2012 at 11:00 am

Thanks

Reply

86 sam March 6, 2012 at 10:32 am

not a big deal , just type :

#date 030613252012
03=March
06=Day
13=Hour
25=Min
2012=Year

That’s IT :)

Reply

87 prabhat March 27, 2012 at 4:01 pm

Hey guys i have tried each and every command to change my linux server time but after i try every command new time is displayed.But when i try to verify it by running date command it shows old time again.Plssss help me……..

Reply

88 sam March 28, 2012 at 9:30 am

my friend this one is working fine nor more no less :

[server#] date 030613252012

it means :
03=March
06=Day
13=Hour
25=Min
2012=Year

That’s IT :)

Reply

89 prabhat singh March 30, 2012 at 2:06 pm

after running this command , do i have to run any other command also?

Reply

90 sam April 3, 2012 at 9:28 am

nothing ;

just to make sure run :
#date

and see the date ;

Reply

91 sunay September 12, 2012 at 8:21 am

its easy to change date or time

Reply

92 Rao September 14, 2012 at 2:22 pm

Helped a lot…Thanks…

Reply

93 Ahamed Bauani October 11, 2012 at 8:28 pm

Thanks a lot for your help. But problem is there is no way to change the date if it is a VPS server :(

Reply

94 Sam October 12, 2012 at 5:31 pm

There is no different between actual server and virtual server ; you can use same command to change the date :

[VPS-server]# date 030613252012

it means :
03=March
06=Day
13=Hour
25=Min
2012=Year

Reply

95 Sam October 17, 2012 at 8:01 pm

Could you please tel me what distribution of linux that you are using ?

Reply

96 hapoint from bpoint October 31, 2012 at 12:58 pm

Thanks :)

Reply

97 dipesh March 15, 2013 at 3:47 pm

This is all awesome guys… many thanks

Reply

98 Ricky1990 April 8, 2013 at 2:11 pm

I really thank you so much because of my wordpress site display wrong date. After read this post, i’ve just changed it. Thanks so much again !

Reply

99 Milton May 11, 2013 at 7:33 am

Very helpful article.

Reply

100 yusuf October 19, 2013 at 11:48 am

HI,

how do i update time one linux machine to another machine via command ?

Reply

101 PRAVEEN November 19, 2013 at 2:10 am

I am getting below error while changing the time. can any one tell me how to resove it.
[cnems@SVT-CSM-01-M:/etc] date 1026140013
date: cannot set date: Operation not permitted
Sat Oct 26 14:00:00 BST 2013
[cnems@SVT-CSM-01-M:/etc]

Reply

102 Sam November 19, 2013 at 6:00 am

Please see the below sample :
[Server#] date 030613252012

it means :
03=March
06=Day
13=Hour
25=Min
2012=Year

Reply

103 sal November 22, 2013 at 7:19 pm

I have a VCX Connect box, a V7005, that accepts some of the commands on this page to change the date however the date is not actually changed. I’ve ran the following to no avail:

# DATE -S “22 NOV 2013 10:00:00″

This in different variations.

Might anyone know if there is another syntax associated with a 3com VCX box?

Reply

104 Sam November 24, 2013 at 5:56 am

have you tried the command that I have shared with you , and what was the output ?

Please see the below sample :
[Server#] date 030613252012

it means :
03=March
06=Day
13=Hour
25=Min
2012=Year

Reply

105 sal November 25, 2013 at 4:35 pm

Hi Sam

I managed to change the time on our VCX Linux box by entering one different variations of the command below. Not sure of the exact syntax but it goes something like this:

# DATE -SET “22 NOV 2013 10:00:00 PST″

It took a short while for the change to reflect on the box and all phones. Short while meaning a few hours.

Reply

106 Sam November 26, 2013 at 8:46 am

Dear ,

Could you please share with me the output of below command ?

# uname -a

Thanks

Reply

107 taufeeq January 12, 2014 at 6:04 am

not working says cannot set date:operation not permitted
what i can do?

Reply

108 Sam January 13, 2014 at 1:51 pm

Check , weather you are root user , or not .
normal user , cant change date .

date -s “YYYY-MM-DD HH:MM:SS”

Reply

109 taufeeq January 18, 2014 at 5:36 am

any trick to change?

Reply

110 sam January 18, 2014 at 7:43 pm

please send me the output of the below command :

# uname -a

Reply

111 taufeeq January 19, 2014 at 7:57 am

[mphs@mphs ~]$ date –set”4 JAN 2014 1:25:00″
date: unrecognized option ‘–set4 JAN 2014 1:25:00′
Try `date –help’ for more information.
[mphs@mphs ~]$ ^C
[mphs@mphs ~]$

Reply

112 Nix Craft January 19, 2014 at 10:57 am

You need to run date as root user:

sudo date --set="4 JAN 2014 13:25:00"

Reply

113 taufeeq January 19, 2014 at 4:08 pm

@Nix craft, its asking password but i don’t know the password and its impossible to know the password bcoz our system admin set its secretly

[mphs@mphs ~]$ sudo date –set=”4 JAN 2014 9:35:00″
[sudo] password for mphs:

Reply

114 Nix Craft January 19, 2014 at 4:55 pm

Try your own password. Also, you need to be root (sysadmin) or part of sysadmin group in /etc/sudoers to change system date. A normal user can not change system date or time due to security reasons.

Reply

115 taufeeq January 20, 2014 at 1:28 pm

ok got it thx for help

Reply

116 sam January 19, 2014 at 9:43 am

Mr. Taufeeq

here is my Skype ID :

mos3535

regards
mosleh

Reply

117 taufeeq January 19, 2014 at 4:04 pm

here is out for # uname -a

[mphs@mphs ~]$ uname -a
Linux mphs 2.6.31.5-127.fc12.i686.PAE #1 SMP Sat Nov 7 21:25:57 EST 2009 i686 i686 i386 GNU/Linux
[mphs@mphs ~]$

Reply

118 sam January 19, 2014 at 8:37 pm

can also please run the below command :

# python -c ‘import platform ; print platform.dist()[0]‘

and send the output here .

Skype : mos3535

Reply

119 taufeeq January 20, 2014 at 4:09 am

[mphs@mphs ~]$ python -c ‘import platform ; print platform.dist[0]‘
Traceback (most recent call last):
File “”, line 1, in
TypeError: ‘function’ object is unsubscriptable
[mphs@mphs ~]$

sorry bro m not on skype

Reply

120 sam January 20, 2014 at 10:47 am

please as I told you , try to change date by supper user like root user:

# su -

if it ask you for password , you should know root password
if not , please create password for root like this :

# passwd root

Reply

121 Maurice March 6, 2014 at 9:17 pm

It even worked on the OLPC XO1

Reply

Leave a Comment

Tagged as: , , , , , , , , , , , , , , , ,

Previous Faq:

Next Faq: