This week's book giveaway is in the Spring forum.
We're giving away four copies of Spring in Action (5th edition) and have Craig Walls on-line!
See this thread for details.
Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!