SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: counting time

  1. #1
    SitePoint Guru
    Join Date
    Sep 2008
    Location
    Dubai
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    counting time

    Hi,

    I am working on closing auction time.

    I let the users choose closing time for their listing, by selecting a given time from <select>thursday 25/12</select> <select>5 pm</select>

    The value stored in databse is say 5 from the day select.

    And 17 from time select.

    Two questions. How could I let the script know 5 is thursday and 17 is 5pm?

    And how I can output 5 to screen so that it become thursday 25/12, and 17 is 5pm

    Appreciate helps.

  2. #2
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You seem to be losing data when you store the date, but want to restore the reduced dataset back to the original full value, this is not really possible.

    How would you know "5" corresponds to December 25th?

    Edit:

    OK, so technically you're not losing data since the number represented by "5" could be the number of days past December 20th, 2008, which sees kind of silly but you might want to specify what exactly that number signifies.
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.

  3. #3
    SitePoint Guru
    Join Date
    Sep 2008
    Location
    Dubai
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the date select which was used to get the value from. If value selected is 5 meaning the the end of the next five days is closing date

    Code PHP:
    <?php
    $aTranslated = array(
    	'french' => array(
            'Lundi',
            'Mardi',
            'Mercredi',
            'Jeudi',
            'Vendredi',
            'Samedi',
            'Dimanche',
    	),
    	'english' => array(
    		'Monday',
    		'Tuesday',
    		'Wednesday',
    		'Thursday',
    		'Friday',
    		'Saturday',
    		'Sunday',
    	),
    );
     
    echo '<select name="end">';
    echo '<option value="0">date/month</option>';
    for ($iCounter = 1 ; $iCounter <= 10 ; $iCounter++ )
    {
    	$iTimeStamp = strtotime(sprintf('+%s Days',$iCounter));
    	echo sprintf('<option value="%s" %s %s>%s %s</option>',
    		$iCounter,
    		($rows['end'] == $iCounter) ? 'selected="selected"' : '',
    		($end == $iCounter) ? 'selected="selected"' : '',
    		$aTranslated['french'][date('w',$iTimeStamp)],
    		date('d/m',$iTimeStamp)
    	);
    }
    echo '</select>';
    ?>

    The array indexes are corresponding for the option values
    Last edited by runrunforest; Dec 28, 2008 at 00:11.

  4. #4
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you recording the day they choose their closing time then? You'll need that value to calculate what you're trying to do.
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.

  5. #5
    SitePoint Guru
    Join Date
    Sep 2008
    Location
    Dubai
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah I store that value to calculate what I am trying to do. The question is how can I do what i am trying to do?

  6. #6
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $referenceTime 'December 20th, 2008';
    $relativeDay   5;
    $time          17;

    echo 
    strtolower(date('l j/n'strtotime("$referenceTime +$relativeDay days"))) . "\n";
    echo 
    date('ga'mktime($time)) . "\n"
    Results:

    Code:
    thursday 25/12
    5pm
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.

  7. #7
    SitePoint Guru
    Join Date
    Sep 2008
    Location
    Dubai
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Very handy.

    What if $referenceTime is a timestamp for example $referenceTime = 1230478336. How would you do it ?

  8. #8
    SitePoint Guru
    Join Date
    Sep 2008
    Location
    Dubai
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just found out the answer myself

    Code PHP:
    echo strtolower(date('l j/n', $refernceTime + ($relativeDay*24*60*60))) . "\n";


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •