Solved

Date manipulation

Posted on 1998-08-03
3
298 Views
Last Modified: 2010-04-21
How can I manipulate the date.
eg:   how can I add days to the current system date?
0
Comment
Question by:kpy
3 Comments
 
LVL 84

Expert Comment

by:ozo
Comment Utility
to change the system date, as super user:
date dammddHHMMccyy
If you want to find tomorrows date (and it's not near midnight the day before a daylight savings time switch)
you can add 86400 to time(2) before calling localtime(3)

time_t t;
char *c;
t = time(NULL);
t += 60*60*24;
c = asctime(localtime(&t));

0
 
LVL 5

Expert Comment

by:ecw
Comment Utility
perl5:
perl -e 'print scalar(localtime(time + 60 * 60 * 24)), "\n"';
0
 

Accepted Solution

by:
almasy earned 100 total points
Comment Utility
To set the system date you can use the "date" command as follows:

    date mmddHHMMyy

Where "mm" represents the month, "dd" the day, "HH" the hour (24-hour format), "MM" the minute, and "YY" the year.  Each value must be two digits.

So for example to set the date to 3:18pm on July 4th, 1976 you would give the command:

    date 0704151876

(The hour is 15 because 3pm is 1500 on a 24-hour clock.)

You must be logged in or su'd to root to set the date.

A good way to update your system clock on a machine connected to the internet is to use the "rdate" command to retrieve the time from a remote system.  The syntax for this command is:

    rdate -s system.name

Where "system.name" is the name of the system you want to retrieve the time from.  The reference system I use is time.mit.edu, so my command is:

    rdate -s time.mit.edu

The "-s" parameter may not be needed on some operating systems.  Again, root access is required to set the system date with this command.

"rdate" is a very useful command to add to the root crontab on a system to keep the date accurate.

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Attention: This article will no longer be maintained. If you have any questions, please feel free to mail me. jgh@FreeBSD.org Please see http://www.freebsd.org/doc/en_US.ISO8859-1/articles/freebsd-update-server/ for the updated article. It is avail…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now