Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

date problem in linux

 
Rocky Salve
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

when i run the date command in fedora, i get the current month
displayed. but if i want to display the previous month how is it
possible anyway.

anyone gotta a bulb!
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It might seem a silly question, but how do you define 'date of the previous month'.

It seems to be easy, i.e.: you take the 15th of July, and the previous month it was the 15th of June.
But what do you do on 30th March?
Do you want the last day of February?
Do you want to substract 30 days?

There are different definitions for 'month' in financial sector, and in law.

I found this 30-days solution (but didn't test it for critical dates):


Perhaps a java solution using GregorianCalendar will be good.
 
Lewin Chan
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
date can do some tricky stuff...

You could do
date -d yesterday
date -d now-30days - which today (apr 11, gives me mar12).

So I would imagine that you could do some kind of lookup based on how many days there are in the month. and then do now-xxxdays to get last month.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic