?
Solved

Date manipulation

Posted on 1998-08-03
3
Medium Priority
?
353 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 200 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

Hello fellow BSD lovers, I've created a patch process for patching openjdk6 for BSD (FreeBSD specifically), although I tried to keep all BSD versions in mind when creating my patch. Welcome to OpenJDK6 on BSD First let me start with a little …
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
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…
Suggested Courses
Course of the Month13 days, 16 hours left to enroll

800 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