Good health to all.
I do one thing, I need a date from yesterday.

$vdate = (date("d")-1).".".date( "mY"); 

The date("d") format gives numbers in the format: 01-31 with zeros.
This is what I need, but my calculation of date ("d") - 1 breaks the format and selects 0 , it seems and understandable:
08-1 = 7 , but how to avoid it?

    2 answers 2

     $vdate = date('dmY', strtotime('yesterday')); 
    • Thank! earned! - I_CaR

    And how about using the Datetime class, it has a very convenient method for this purpose .
    IMHO, it is much easier to manipulate a class than a string.
    I now can not understand why people create a tangled code in which, sometimes, they themselves can not figure it out.

    • I don’t mind using classes, but in this case is it easier ?: $ date = new DateTime (); $ date-> sub (new DateInterval ('P1D')); $ vdate = $ date-> format ('dmY'); - inso
    • one
      @inso on the taste and color of all the markers are different. Not far more than yesterday I discussed a similar moment with a colleague and agreed that 3 lines of quickly readable code are better than one not so much. In this case, it all depends on whom it is more convenient to use which tool for everyday tasks;) - zenith
    • under "3 lines of fast-readable code" I meant that you shouldn’t really strain yourself to understand and the code is read by the programmer as plain text. - zenith