10

I have 2 functions for checking if today is the first day of the month. Does one of these have an advantage over the other, ie accuracy?

if(date('j', $timestamp) === '1') { }

if(date('Y-m-d') == date('Y-m-01')) { }
Naterade
  • 2,635
  • 8
  • 34
  • 54
  • there are may ways to do most things –  Jul 31 '13 at 22:13
  • 2
    second method is slower, because you call date two times. accuracy is the same. – Karim Jul 31 '13 at 22:14
  • 1
    The second uses two conversions to strings, then compares resulting strings. That is considered a bad practice in my book. – ppeterka Jul 31 '13 at 22:14
  • Downvote was not needed. The question is not a duplicate. I'm not asking how to do it but if one holds an advantage. – Naterade Jul 31 '13 at 22:22
  • hello sorry for comment in here where define variable of '$timestamp' i have similiar problem in here http://stackoverflow.com/questions/35375112/increase-field-in-mysql-every-early-month – Freddy Sidauruk Feb 13 '16 at 06:45

1 Answers1

12

The first one does less checking I would use that.

You also don't need the timestamp argument if you want to check now / today

exussum
  • 18,275
  • 8
  • 32
  • 65