LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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

Reply
 
Search this Thread
Old 08-23-2004, 10:12 AM   #1
swinchen
Member
 
Registered: Apr 2004
Location: Maine (USA)
Distribution: Slackware 9.1
Posts: 45

Rep: Reputation: 15
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.
 
Old 08-23-2004, 10:43 AM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 58
You can use time(NULL) - 86400; as the current time?
 
Old 08-23-2004, 11:26 AM   #3
swinchen
Member
 
Registered: Apr 2004
Location: Maine (USA)
Distribution: Slackware 9.1
Posts: 45

Original Poster
Rep: Reputation: 15
No... that doesnt seem to work....
 
Old 08-23-2004, 11:30 AM   #4
swinchen
Member
 
Registered: Apr 2004
Location: Maine (USA)
Distribution: Slackware 9.1
Posts: 45

Original Poster
Rep: Reputation: 15
Found it!!! To get the previous day... do something like this:

date +%y%m%d --date="-1 day"
 
Old 08-23-2004, 11:39 AM   #5
arvind_sv
Member
 
Registered: Oct 2002
Location: Bangalore
Distribution: Gentoo Linux
Posts: 96

Rep: Reputation: 15
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.
 
Old 08-23-2004, 11:47 AM   #6
b0ng
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: Reputation: 15
#!/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.
 
Old 08-23-2004, 12:17 PM   #7
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 58
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Timestamp of previous command issued benjaminrtz Linux - General 1 04-16-2005 01:53 AM
date command aetucker1 Linux - General 3 01-21-2005 12:57 PM
can I use date command with mkdir? ewto Linux - General 6 06-16-2004 08:47 AM
Command of the day! coolamit78 LQ Suggestions & Feedback 12 04-22-2004 08:13 AM
Setting date day names Dark Carnival Linux - General 3 12-07-2003 01:22 PM


All times are GMT -5. The time now is 02:37 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration