date() function

This is a discussion on date() function within the PHP General forums, part of the PHP Programming Forums category; I noticed that if I do something like this: $prevminute = date("i")-1; ..and the current minute happens ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 11-14-2006
Ashley M. Kirchner
 
Posts: n/a
Default date() function


I noticed that if I do something like this:

$prevminute = date("i")-1;

..and the current minute happens to be '05', $prevminute becomes '4'
- I lose the padding. How can I ensure that I retain that padding? I
suppose a crud solution is to run $prevminute through an if loop to see
if it's < 10. But I'm wondering if there's a better way.

--
W | It's not a bug - it's an undocumented feature.
+--------------------------------------------------------------------
Ashley M. Kirchner <mailto:ashley@pcraft.com> . 303.442.6410 x130
IT Director / SysAdmin / Websmith . 800.441.3873 x130
Photo Craft Imaging . 3550 Arapahoe Ave. #6
http://www.pcraft.com ..... . . . Boulder, CO 80303, U.S.A.
Reply With Quote
  #2 (permalink)  
Old 11-14-2006
Brad Fuller
 
Posts: n/a
Default RE: [PHP] date() function



$prevminute = sprintf('%02s', date("i")-1);


> -----Original Message-----
> From: Ashley M. Kirchner [mailto:ashley@pcraft.com]
> Sent: Tuesday, November 14, 2006 1:17 PM
> To: PHP General List
> Subject: [php] date() function
>
>
> I noticed that if I do something like this:
>
> $prevminute = date("i")-1;
>
> ..and the current minute happens to be '05', $prevminute becomes '4'
> - I lose the padding. How can I ensure that I retain that padding? I
> suppose a crud solution is to run $prevminute through an if loop to see
> if it's < 10. But I'm wondering if there's a better way.
>
> --
> W | It's not a bug - it's an undocumented feature.
> +--------------------------------------------------------------------
> Ashley M. Kirchner <mailto:ashley@pcraft.com> . 303.442.6410 x130
> IT Director / SysAdmin / Websmith . 800.441.3873 x130
> Photo Craft Imaging . 3550 Arapahoe Ave. #6
> http://www.pcraft.com ..... . . . Boulder, CO 80303, U.S.A.
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

Reply With Quote
  #3 (permalink)  
Old 11-15-2006
Ivo F.A.C. Fokkema
 
Posts: n/a
Default RE: [PHP] date() function

On Tue, 14 Nov 2006 15:11:56 -0500, Brad Fuller wrote:

>
>
> $prevminute = sprintf('%02s', date("i")-1);


Or, $prevminute = str_pad(date("i")-1, 2, '0', STR_PAD_LEFT);

It's a little more code - don't ask me about the speed :)

Ivo
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:00 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0