Solved

Date manipulation

Posted on 1998-08-03
3
335 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
ID: 2009197
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
ID: 2009198
perl5:
perl -e 'print scalar(localtime(time + 60 * 60 * 24)), "\n"';
0
 

Accepted Solution

by:
almasy earned 100 total points
ID: 2009199
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…

828 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