Author Topic: I love strtotime  (Read 1444 times)

Mike

  • Jackass In Charge
  • Posts: 11257
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
I love strtotime
« on: November 01, 2011, 11:44:24 AM »
For the report writer I built I have date fields that I then pass through strtotime which allows a lot of flexibility in how the date is formatted.  And since I don't resolve the date until the report is ran it also allows for the use of relative dates (i.e.:  yesterday, today, monday this week, etc).

Well we are now adding in a job that runs at the end of the work day, so I wanted a report that would get the results from that job but it wouldn't be ran until the next day.  So a date range of "yesterday" - "yesterday" works except on Mondays when you'd want to go back to Friday's job and get it.  Found the answer:  "last weekday" - "yesterday".  Fucking love that function.  Adds so much flexibility with no additional work on my part.

ober

  • Ashton Shagger
  • Ass Wipe
  • Posts: 14310
  • Karma: +73/-790
  • mini-ober is taking over
    • Windy Hill Web Solutions
Re: I love strtotime
« Reply #1 on: November 01, 2011, 02:01:44 PM »
Yeah, that's an amazing little function.

micah

  • A real person, on the Internet.
  • Ass Wipe
  • Posts: 6915
  • Karma: +58/-55
  • Truth cannot contradict truth.
    • micahj.com
Re: I love strtotime
« Reply #2 on: November 01, 2011, 03:49:10 PM »
it has its quirks*, but yeah, its probably one of the neatest little off-the-shelf functions in PHP



*
1/2/2011 is January 2
1-2-2011 is February 1
"I possess a device, in my pocket, that is capable of accessing the entirety of information known to man.  I use it to look at pictures of cats and get in arguments with strangers."

Mike

  • Jackass In Charge
  • Posts: 11257
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Re: I love strtotime
« Reply #3 on: November 01, 2011, 04:35:34 PM »
Due to the quirks (big one for me is weeks starting on Monday instead of Sunday) when I did the report writer I had those feels validate via JS.  What it'd do is make an ajax call with the string in question and it would return if it was valid or not and if so what it resolved to.

Which of course meant I had to adjust make server's clock to test that "last weekday" on a Monday would go back to Friday.