Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
08-23-2004, 10:12 AM
|
#1
|
Member
Registered: Apr 2004
Location: Maine (USA)
Distribution: Slackware 9.1
Posts: 45
Rep:
|
date command getting previous day
Is there any way to get the previous day in linux?
I want something like date +%y%m%d .... but the pervious day.
for example,
date +%y%m%d
040801
but I want the previous day... so it should output
040731
Thanks.
|
|
|
08-23-2004, 10:43 AM
|
#2
|
Senior Member
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246
Rep:
|
You can use time(NULL) - 86400; as the current time?
|
|
|
08-23-2004, 11:26 AM
|
#3
|
Member
Registered: Apr 2004
Location: Maine (USA)
Distribution: Slackware 9.1
Posts: 45
Original Poster
Rep:
|
No... that doesnt seem to work....
|
|
|
08-23-2004, 11:30 AM
|
#4
|
Member
Registered: Apr 2004
Location: Maine (USA)
Distribution: Slackware 9.1
Posts: 45
Original Poster
Rep:
|
Found it!!! To get the previous day... do something like this:
date +%y%m%d --date="-1 day"
|
|
|
08-23-2004, 11:39 AM
|
#5
|
Member
Registered: Oct 2002
Location: Bangalore
Distribution: Gentoo Linux
Posts: 96
Rep:
|
Hi,
Try this:
date +%y%m%d -d '1 day ago'
Arvind
PS: Ah, I see you found it yourself, just when I was replying.
Last edited by arvind_sv; 08-23-2004 at 11:40 AM.
|
|
|
08-23-2004, 11:47 AM
|
#6
|
LQ Newbie
Registered: Aug 2004
Location: Location??? Where I am is top secret, if I tell you, I have to kill you.
Distribution: College, Slack
Posts: 24
Rep:
|
#!/usr/bin/perl
$_ = `date`;
@date = split /\s/;
#print "@date[2]";
@date[2]--;
print "@date\n";
#That should do what you want.
haha, you guys did it while, I was writing my script.
Last edited by b0ng; 08-23-2004 at 12:56 PM.
|
|
|
08-23-2004, 12:17 PM
|
#7
|
Senior Member
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246
Rep:
|
This is what I meant:
Code:
itsme@dreams:~/C$ cat prevday.c
#include <stdio.h>
#include <time.h>
int main(void)
{
time_t now;
now = time(NULL);
printf("Today is: %s", ctime(&now));
now -= 86400;
printf("Yesterday was: %s", ctime(&now));
return 0;
}
itsme@dreams:~/C$ ./prevday
Today is: Mon Aug 23 10:16:26 2004
Yesterday was: Sun Aug 22 10:16:26 2004
|
|
|
All times are GMT -5. The time now is 12:38 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|