• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

date problem in linux

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
World domination requires a hollowed out volcano with good submarine access. Tiny ads are optional.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic