Re: I am lost on date()
| From: | Randi Andersen | Date: | Wed, 26 Jul 2000 20:41:02 +0000 |
| Subject: | Re: I am lost on date() | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-8406@lists.php.net to get a copy of this message | ||
If you have a string you might want to treat
is as such and not involve date() at all? I'm
sure there's an elegant way of doing this with
date, but the following describes a "string" way.
This is tested with the time you mentioned
(and whith 17:05:22 to make sure it doesn't chop
off anything if first digit isn't a zero).
<?php
$createdtime='07:05:22'; //just testing with this...
//you'd stick your timestamp here
echo "$createdtime is the unformatted time<br>";
$first_digit=substr($createdtime,0,1);
//this picks out 1 character in position 0
//which is the start of the string
if ($first_digit==0)
{
$createdtime=substr($createdtime,1,7);
//return the 7 last (from position 1 and onwards)
//characters if first digit is zero
}
echo "$createdtime is stripped of the leading zero (if any)";
?>
Generic Player wrote:
<snip>
> I just want to chop off the
> leading 0 on a date such as 07:05:22.
</snip>