Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

date problem in linux  RSS feed

 
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!
 
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.
 
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!