Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Weeks comparison

 
Asheesh Nehra
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to compare two dates if these dates are of same week, how can i do it in javascript any HELP.!!!
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sounds like you want to use the Date Object

Eric
 
Asheesh Nehra
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply, My problem is that I have to compare two dates and determine if they are of the same week. here is no method which take parameter date and return week of the year.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Than build one. Get the day of the week for the first day. [S,M,T,W,T,F,S] subtract the number of days to get the start of the week. See if the other date is greater than the start date. If it is, add seven days and see if it is less than or equal to this new date. If it is, you know it is in the range of the week.

Other option is you take your two days and make them both go to the first day of the week. See if they are the same day. [probably a simpler solution!]

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic