Solved

Date manipulation

Posted on 1998-08-03
3
316 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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 …
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

863 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

19 Experts available now in Live!

Get 1:1 Help Now