Win a copy of Transfer Learning for Natural Language Processing (MEAP) this week in the Artificial Intelligence and Machine Learning 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 ...
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Carey Brown
  • Frits Walraven

date problem in linux

Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
  • 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.
Everybody's invited. Except this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic