3

In JQuery, I want to take a string such as "first Sunday" or "third Wednesday" and get back the unix timestamp of that day for the current month.

I've seen this done before in PHP with strtotime() or the DateTime class, but I can't find out how you do this in JQuery.

EDIT: This is not a duplicate of Javascript equivalent of php's strtotime()?

I needed something specifically that could handle passing in "first" or "second" etc ... unless I'm mistaken, I can't do that with javascripts Date, and have thus accepted an answer on this page for referring me over to Datejs.

Community
  • 1
  • 1
matt
  • 223
  • 4
  • 13
  • 2
    This may lead to a hint ... http://stackoverflow.com/questions/4048204/javascript-equivalent-of-phps-strtotime – Orangepill May 21 '13 at 06:11
  • thanks for the hint .... turns out that datejs is exactly what I need. That SO is useful but there is no usage I can see of taking the text parameters like the ones I listed in the question. – matt May 21 '13 at 06:26
  • `jQuery` doesn't have any date manipulation functions. You may take a look at [`datejs`](http://www.datejs.com/) instead. – Darin Dimitrov May 21 '13 at 06:13
  • Darin, this works, I verified this at http://code.google.com/p/datejs/ – matt May 21 '13 at 06:19

1 Answers1

6

Datejs will make all your date operations a snap. To answer your Question, finding the 3rd Sunday of this month would be :

Date.today().third().sunday();
Ja͢ck
  • 170,779
  • 38
  • 263
  • 309
xShirase
  • 11,975
  • 4
  • 53
  • 85