SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Thread: date format

  1. #1
    SitePoint Member
    Join Date
    Aug 2004
    Location
    Geneva
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    date format

    Hello,

    PHP Code:
    for($m 0;$m <= 0$m++)
    {
    $now date ("Y-m-d"mktime (0,0,0,date("m"),date("d")+$m,date("Y")));
    echo 
    "<input type=\"hidden\" name=\"open_date\" value=\"" $now "\">";

    With this piece of code I want to get the following format with the hour and the minutes :
    20-05-2009 10:00

    Do you know how to modify?

    Thanks,

    seb

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Your dates will never have an hour or a minute (you've specified they're 0 and 0 in the mktime call), so what's the point?

    If you do have a date with a time you want to format like that, the PHP manual is the right place to go:
    http://us3.php.net/manual/en/function.date.php

    date('d-m-Y H:i')

  3. #3
    SitePoint Member
    Join Date
    Aug 2004
    Location
    Geneva
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Replacing the date format function with yours date("d-m-y G:i"); gives this result : 0000-00-00

    Any idea?

    seb

  4. #4
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You have a loop which runs 1 time (why is there a loop?) and adds 0 to the current date (why?)

    Is there really more going on than that?

    date("d-m-y G:i") alone wouldn't print 0000-00-00. Are you trying to insert this into a database or something?

  5. #5
    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)
    Why and how many iteration you want to do is still up to you but formatting the dates is simple:
    PHP Code:
    echo date('d-m-Y H:i'); // formatted date of today/now
        
    $date '2009-05-20 15:10:00';
    echo 
    date('d-m-Y H:i'strtotime($date)); // formatted date of $date 2009-05-20 15:10:00
    echo date('d-m-Y H:i'strtotime('+1 day'strtotime($date))); // next day of $date 
    Hope this points to the right direction.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  6. #6
    SitePoint Member
    Join Date
    Aug 2004
    Location
    Geneva
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    @rajug and Grossman

    Yes, of course, this has to be insert into a db.
    FYI here is the complete code of the page:

    PHP Code:
    <?
    include 'header.php';
    include 
    'format.css';
    $queryu "SELECT * FROM $userstable WHERE (userlevel = '2' OR userlevel = '3' OR userlevel = 'A') AND username = '$tmpname'";
    $resultu mysql_query($queryu); 
    $rowumysql_fetch_array($resultu);
    $userlevel $rowu['userlevel'];

    if(
    $userlevel == '2'){
    // DO NOTHING
    echo "<table bgcolor=\"#ECECEC\" cellpadding=\"3\" cellspacing=\"0\" align=\"center\" class=\"black\" border=\"0\">";
    echo 
    "<tr>";
    echo 
    "<td>You must have manager access to enter this area.</td>";
    echo 
    "</tr><table>";
    }else{
    //ELSE, SHOW FORM BELOW - Begin manager form
    include 'includes/inputcheck.php';
    echo 
    "<td>";

    echo 
    "<table bgcolor=\"#ECECEC\" cellpadding=\"3\" cellspacing=\"0\" align=\"center\" class=\"black\" border=\"0\">";
    echo 
    "<tr><td bgcolor=\"#ECECEC\" align=\"center\"><b>Task Creation</b></td><td bgcolor=\"#F2F2F2\" align=\"center\"><b>Customer Maintenance</b></td></tr>";
    echo 
    "<tr><td>";

    echo 
    "<table bgcolor=\"#ECECEC\" cellpadding=\"3\" cellspacing=\"0\" align=\"center\" class=\"black\">";
    echo 
    "<tr><form name=\"form1\" method=\"post\" onSubmit=\"return (formCheck(this))\" action=\"complete.php?getid=1\">";
    echo 
    "<td align=\"right\"><b>Customer:</b></td> ";
    echo 
    "<td><select name=\"catname\">";
    echo 
    "<option value=\"\"></option>";
    include 
    'includes/catecon.php';
    echo 
    "</select></td></tr>";
    /*for($m = 0;$m <= 0; $m++){
        $now = date("Y-m-d h:i", strtotime("now + $m day"));
        echo "<input type='hidden' name='open_date' value='$now' />\n";
    }*/
    for($m 0;$m <= 0$m++)
    {
    $now date ("Y-m-d"mktime (0,0,0,date("m"),date("d")+$m,date("Y")));
    echo 
    "<input type=\"hidden\" name=\"open_date\" value=\"" $now "\">";
    }
    /*echo "<tr><td align=\"right\"><b>Priority:</b></td><td><select name=\"priority\">";
    echo "<option value=\"\"></option>";
    include 'includes/priorcon.php';
    echo "</select> <font size=\"1\">Lower numbers are higher priority</font></td></tr>";*/
    echo "<tr><td align=\"right\"><b>Customer Site:</b><td><input type=\"text\" name=\"site\" value=\"\" size=\"25\"><br></td></tr>";
    echo 
    "<tr><td align=\"right\"><b>Modem #:</b><td><input type=\"text\" name=\"modem\" value=\"\" size=\"25\"><br></td></tr>";
    echo 
    "<tr><td align=\"right\"><b>Task Name:</b><td><input type=\"text\" name=\"title\" value=\"\" size=\"25\"><br></td></tr>";
    echo 
    "<tr><td align=\"right\"><b>Description:</b><td><textarea name=\"description\" cols=\"25\" rows=\"5\"></textarea><br></td></tr>";
    echo 
    "<tr><td align=\"right\"><b>Assignee:</b></td><td><select name=\"personnel\">";
    echo 
    "<option value=\"\"></option>";
    include 
    'includes/personnel.php';
    echo 
    "</select></td></tr>";
    echo 
    "<tr><td align=\"right\"><b>Caller's Name:</b><td><input type=\"text\" name=\"caller\" value=\"\" size=\"25\"><br></td></tr>";
    echo 
    "<tr><td align=\"right\"><input type=\"submit\" value=\"Submit Task\"></td></tr>";
    echo 
    "<tr><td align=\"center\" colspan=\"2\">";
    echo 
    "</form></td></tr></table>";
    echo 
    "</td>";

    echo 
    "<td bgcolor=\"#F2F2F2\" valign=\"top\"><br>";
    echo 
    "<table width=\"70%\" cellpadding=\"3\" cellspacing=\"0\" align=\"center\" class=\"black\" border=\"0\">";
    $sql "SELECT * FROM $taskstable WHERE taskid = '$taskid' GROUP BY open_date";
    $result mysql_query($sql);
    $row mysql_fetch_array($result);
    echo 
    "<form name=\"form2\" method=\"post\" onSubmit=\"return (formCheck(this))\" action=\"complete.php?getid=112\">";
    echo 
    "<tr><td align=\"right\" colspan=\"2\"><b>Add:</b> <input type=\"text\" name=\"catname\" value=\"\" size=\"20\"> <input type=\"submit\" value=\"Add Customer\"></td></tr></form>";

    echo 
    "<form name=\"form2\" method=\"post\" action=\"complete.php?getid=56\"><tr><td align=\"right\" colspan=\"2\"><br> <b>Delete:</b> 
    <select name=\"catnamedel\"><option value=\"\"></option>"
    ;
    include 
    'includes/catecon.php';
    echo 
    "</select> <input type=\"submit\" value=\"Delete Customer\"></td>";
    echo 
    "</tr></form>";
    echo 
    "</table>";

    echo 
    "</td>";
    echo 
    "</tr><table>";

    echo 
    "<br><br></td>";
    echo 
    "</tr>";
    echo 
    "</table>";
    }
    /*include 'footer.php';*/

    ?>

  7. #7
    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)
    What is the purpose of this loop actually?
    PHP Code:
    for($m 0;$m <= 0$m++){
     
    //

    If this is fixed one time loop then why have you used the loop? And what date you are trying to print in the field?
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  8. #8
    SitePoint Member
    Join Date
    Aug 2004
    Location
    Geneva
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't know the purpose of this loop but something's probably wrong with it...


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
  •