Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Date manipulation

Posted on 1998-08-03
3
Medium Priority
?
364 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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.
Suggested Courses

604 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