OpenBSD Set Date and Time Command

I am a new OpenBSD system user. How do I set new date and time under an OpenBSD UNIX server or desktop?

You can set date and time using date command on OpenBSD. You must be a root user i.e. login as root user either using the su command or doas command. When you run date command without any arguments, the command displays the current system date and time. This page shows how to set data and time on OpenBSD based system using the CLI.

OpenBSD see the current data and time

Simply type the following date command:
$ date
OpenBSD see the current data and time command

OpenBSD set date and time command

The syntax is as follows:
date yyyymmddhhss
Run it via the doas command:
doas date yyyymmddhhss

  • yyyy – Year
  • mm – Month
  • dd – Day
  • HHSS – Hour Second in 24 clock format
WARNING! These examples requires root level privileges (you must login as root).

Set the date to May 10, 1985, 4:27 PM, enter:
# date 198505101627
$ doas date 198505101627
Set the time to 3:42 PM, without modifying the date, enter
# date 1542
$ doas date 1542
To display current date and time, enter date command without option:
$ date
Sample outputs:

Fri May 10 15:42:01 IST 1985

How to automatically set correct date and time without using date command

Simply run the following command:
$ doas ntpd -s
OpenBSD Set Date and Time Commands
I strongly suggest that you configure ntpd on OpenBSD to sync date and time (clock) using the Internet. The default config file /etc/ntpd.conf should work without any problems. Here is my ntpd.conf disaplyed using the ntpd command $ doas rcctl enable ntpd
$ doas rcctl start ntpd
$ doas rcctl ls started

How to display date and time in specific format on OpenBSD

The syntax is:
date +"format"
To display the date using the specified format string:
$ date +"%d/%m/%Y"
$ echo "Today is `date +'%A, %B %d %Y'`"
date "+DATE: %Y-%m-%d%nTIME: %H:%M:%S"

OpenBSD see date and time in custom format

An date command with a leading plus sign (+) signals a user-defined format:

  • %Y : Year
  • %m : Month
  • %d : Day
  • %n : New line
  • %H : Hour
  • %M : Minutes
  • %S : Seconds
  • %A : Full weekday name
  • %B : Full month name

See strftime(3) man page for full list of format here.


You just learned about setting up date and time on OpenBSD. I strongly suggest you read the man pages for more info using the man command:
man 3 strftime man date

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

🐧 1 comment 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
1 comment… add one
  • pawciobiel Nov 20, 2017 @ 17:33

    One can also set it via ntp with `doas ntpd -s`

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