How to set date in Ubuntu using terminal?

Getting your system date from an Ubuntu terminal

First, to get your current Date, use the date command

date +%Y%m%d

For example, printing the Date:

ubuntu@codetryout:~$ date +%Y%m%d
20210105

Setting the system date from commandline

Now, Setting the date and time using the -s switch

date +%Y%m%d -s 20201201

Testing

Let us test it:

ubuntu@codetryout:~$ date
Tuesday 05 January 2021 07:00:05 AM IST

ubuntu@codetryout:~$ sudo date +%Y%m%d -s 20201201
20201201

ubuntu@codetryout:~$ date
Tuesday 01 December 2020 12:00:03 AM IST

Note: This is tested on Ubuntu 20.04. Date command is common across all Linux distributions, will work on Any Linux / Debian distros.