Re: adding leading zeros to a date



ZeldorBlat wrote:
Alternatively:

$InDate = date('Y-m-d', mktime(0, 0, 0, $inmonth, $inday, $inyear));


Slight overkill, don't you think? That's like using a regular expression to append something to a string.


Either the sprintf() methohd is cleaner, or something that is explicitly obvious what's going on, like:

$InDate = ($inyear . "-"
	. (($inmonth < 10) ? "0" : ""). $inmonth . "-"
	. (($inday < 10) ? "0" : "") . $inday);

--
Oli
.



Relevant Pages

  • Re: How to left pad a string with spaces?
    ... How do I use sprintf to convert the string so it has 4 spaces padded on ... If copying takes place between objects that overlap, ... What would happen if myvar were defined as ...
    (comp.lang.c)
  • Re: Code stops for no apparent reason
    ... This can cause very odd errors, ... Cleaner is a "must have" for serious Excel developers. ... Dim strSheetName As String, strSheetName2 As String, strChartTitle ...
    (microsoft.public.excel.programming)
  • Re: How to left pad a string with spaces?
    ... How do I use sprintf to convert the string so it has 4 spaces padded on ... If copying takes place between objects that overlap, ... What would happen if myvar were defined as ...
    (comp.lang.c)
  • Re: Partial string loss with sprintf/strcat
    ... string the device is sending is missing it's header. ... sprintf(tmpMsg, ... sprintf(Message, "%04d%s", len, tmpMsg); ... The entire header appears to be getting lost. ...
    (comp.lang.c)
  • Re: sprintf
    ... On the other hand, I'm free to use sprintf(), so I can convert everything I want to print into a string and then forward that string to PrintOnConsole. ... My problem now is that I don't know how many characters sprintf() will put in the buffer provided as first input argument. ... float GimmeAFloat ...
    (comp.lang.c)