SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    get all times between these two variables

    Hi guys


    I need to pull every time in 20 minutes intervals

    I tried the code below but it is not working


    PHP Code:
    $start="2010-03-03 11:40:00";
    $end="2010-03-03 15:00:00";


    for(
    $i $start$i $end$i += 20 60){

    echo
    "$i";



  2. #2
    SitePoint Evangelist AlienDev's Avatar
    Join Date
    Feb 2007
    Location
    UK
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to use strtotime() on $start and $end.
    Me on StackOverflow | Blog & personal website.

    I mostly use: PHP, Java, JavaScript, Android.

  3. #3
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $start strtotime("2010-03-03 11:40:00"); 
    $end strtotime("2010-03-03 15:00:00"); 
    for(
    $i $start$i $end$i += 1200){ 
        echo 
    date('Y-m-d H:i:s'$i) . '<br />';

    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  4. #4
    SitePoint Guru
    Join Date
    Oct 2004
    Location
    uk
    Posts
    853
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys

  5. #5
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    php 5.3 goodness
    PHP Code:
    foreach (new DatePeriod(new DateTime($start), new DateInterval('PT20M'), new DateTime($end)) as $dt) {
        echo 
    $dt->format('Y-m-d H:i:s'), "\n";

    Kinda verbose though :/


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
  •