• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Gregorian calendar subtract

 
Ranch Hand
Posts: 99
Tomcat Server Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys,

Im trying to subtract 1 day from a date using Calendar but didnt work.

 
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps DAY_OF_WEEK is not the right constant to use? (Hint: it's not.)

And the rest of that code looks rather, er, odd. What else are you trying to do besides subtract?
 
Mauro Trevigno
Ranch Hand
Posts: 99
Tomcat Server Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Perhaps DAY_OF_WEEK is not the right constant to use? (Hint: it's not.)

And the rest of that code looks rather, er, odd. What else are you trying to do besides subtract?



Which is the right constant to use?

Actually i just realize what was the mistake.



Thanks
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mauro Trevigno wrote:
if(Day == 1 || Day == 7)



Don't use those magic numbers. Use the appropriate contsants instead.
 
Bear Bibeault
Sheriff
Posts: 67595
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would use DATE rather than DAY_OF_WEEK.
 
Master Rancher
Posts: 4052
56
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Perhaps DAY_OF_WEEK is not the right constant to use? (Hint: it's not.)


Hint: yes it is. An add() using DAY_OF_WEEK has exactly the same effect as an add using DATE, DAY_OF_MONTH, or DAY_OF_YEAR. A get(), set(), or roll() will behave differently, but not add() - the date/time gets adjusted the same way for any of those constants I just listed. We may regard DAY_OF_WEEK as less intuitive to us to use here, but the effect is the same. And of course, for the part of the code that depends on get() above, DAY_OF_WEEK is the correct field to use, since it's code that's trying to skip Saturday and Sunday.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic