Re: sscanf does not rpad zeros?
| From: | Jeffery Cann | Date: | Thu, 09 Nov 2000 02:14:35 +0000 |
| Subject: | Re: sscanf does not rpad zeros? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-24417@lists.php.net to get a copy of this message | ||
The scan expression should be: "%02s/%02s/%4s
to obtain a zero-padded month:
Date: 06/15/2003
MM: 06
DD: 15
YYYY: 2003
Jeffery Cann wrote:
> Greetings.
>
> The following bit of code:
>
> <?php
> $Date = "06/15/2003";
> sscanf( $Date, "%02d/%02d/%4d", &$DateMM, &$DateDD, &$DateYYYY );
> print "date: $Date<br>";
> print "MM: $DateMM<br>";
> print "DD: $DateDD<br>";
> print "YYYY: $DateYYYY<br>"
> ?>
>
> produces this output:
>
> Date: 06/15/2003
> MM: 6
> DD: 15
> YYYY: 2003
>
> Notice that for $DateMM, I specified '%02d", yet the parsed month is '6'
> and not '06'. I want the parsed month to be zero padded. Have I missed
> something? Possibly this is a bug?
>
> According to Example 1 in the PHP manual for sprintf
> (http://www.php.net/manual/html/function.sprintf.html) the correct
> format for zero padded integers is:
>
> sprintf ("%04d-%02d-%02d", $year, $month, $day);
>
> Thanks
> Jeff
>
> --
> jccann [at] home [dot] com
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
--
jccann [at] home [dot] com