#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    61
    Rep Power
    14
    Snow again? I just can't catch the drift when dealing with dates and times.

    First I need a simple script to convert a "human" entered date (ie 12-9-2000) from a form to unix time. Can I use a <input text... >?

    Then I need to convert unix time back into a "human" form to display when reading to a page. Again 12-9-2000.

    All this time I am having trouble setting up mySQL table. Do I set the startdate and enddate columns as INT or TIMESTAMP.

    As you can see I am really lost here. php manual doesn't seem to break it down to my level. Are there any tutorial pages out there that address time issues on a newbie level?

    Thanks,
    stujo
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2000
    Location
    Ontario, Canada
    Posts
    498
    Rep Power
    18
    First I need a simple script to convert a "human" entered date (ie 12-9-2000) from a form to unix time. Can I use a <input text... >?

    Do this to set the timestamp in PHP:
    $unixtime = mktime(0,0,0,12,9,2000);

    Then I need to convert unix time back into a "human" form to display when reading to a page. Again 12-9-2000.

    Again, do this in PHP:

    echo date('d-m-Y',$unixtime);

    All this time I am having trouble setting up mySQL table. Do I set the startdate and enddate columns as INT or TIMESTAMP.

    Your best bet is to make the MySQL row a long int to store the timestamp.



    ------------------
    To alcohol! The cause of, and solution to, all of life's problems. -- Homer Simpson
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    61
    Rep Power
    14
    1/2 way there. I have entered through a form a date to the columns 'day1' and 'enddate' set as bigint. I manually calculated the data (969854400 is Sept. 25,2000 and 969940800 is the 26th).

    When I go to put them on a page I get the infamous 12-31-1969. I have tried everything except duct tape and bailling wire to get this thing to work, including the above suggestion in enough variations that I am more confused than ever. Any other way around this beast?
  6. #4
  7. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15
    Take a look at the following article:
    http://www.phpbuilder.com/columns/akent20000610.php3

    ------------------
    SR -
    webshiju.com
    www.jobxyz.com-IT Career Portal
    ezipindia.com--WebStudio


    "The fear of the LORD is the beginning of knowledge..."
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    61
    Rep Power
    14
    Thanks for replying. I have read that one a few times and did again just to make sure. I am still getting 12-31-1969 or forms of it.

    I should have included my code on the first try. Perhaps someone can see my problem. Here it is without all the fluff.
    *****************
    <html>
    <body>
    <?php
    $db = mysql_connect("localhost", "xxxxx", "xxxxxx");
    mysql_select_db("xxxxxx",$db);

    $result = mysql_query("SELECT * FROM calendar ORDER by day1 ASC", $db);
    if ($myrow = mysql_fetch_array($result))
    {
    echo "<table border=0 width=98% cellspacing=5>n";
    do {

    $date_time_array1 = getdate ($day1);
    $start = $date_time_array[ "weekday,month,mday,year"];

    $date_time_array2 = getdate ($enddate);
    $end = $date_time_array[ "weekday,month,mday,year"];

    printf("<tr><td valign=top ><b>%s</b> , On <b>$start</b> at <b>%s</b> and ending on <b>$end</b> </td></tr><tr><td valign=top >%s</td></tr><tr><td><b>Address: </b>%s&nbsp;&nbsp;&nbsp;<b>City: </b>%s&nbsp;&nbsp;&nbsp;<b>State: </b>%s</td></tr><tr><td valign=top><b>Contact: </b>&nbsp;%s &nbsp;&nbsp;&nbsp; %s &nbsp;&nbsp;&nbsp; $email &nbsp;&nbsp;&nbsp; $url<BR><BR></td></tr>n", $myrow["event"], $myrow["time"], $myrow["words"], $myrow["address"], $myrow["city"], $myrow["state"], $myrow["contact"], $myrow["phone"]);

    } while ($myrow = mysql_fetch_array($result));
    echo "</table>n";
    } else {
    echo "Sorry, no records were found!";
    }
    ?>
    </center>
    </body>
    </html>
    *********************
    Again thanks for all the help. I am past feeling like an idiot on this one.

    stujo
  10. #6
  11. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    <<
    $date_time_array1 = getdate ($day1);
    $start = $date_time_array[ "weekday,month,mday,year"];

    $date_time_array2 = getdate ($enddate);
    $end = $date_time_array[ "weekday,month,mday,year"];
    >>


    yea, i am not sure from where you are getting the $day1,$enddate varaiable
    if it is coming from the database then you have to add following things in your code:

    $day1=$myrow["day1"];
    // i guess your field name is day1.

    $enddate=$myrow["enddate"];
    // i guess your field name is enddate.


    $date_time_array1 = getdate ($day1);
    $start = $date_time_array1[ "weekday,month,mday,year"];

    $date_time_array2 = getdate ($enddate);
    $end = $date_time_array2[ "weekday,month,mday,year"];

    ------------------


    Here is the complete code:

    <html>
    <body>
    <?php
    $db = mysql_connect("localhost", "xxxxx", "xxxxxx");
    mysql_select_db("xxxxxx",$db);

    $result = mysql_query("SELECT * FROM calendar ORDER by day1 ASC", $db);
    if ($myrow = mysql_fetch_array($result))
    {
    echo "<table border=0 width=98% cellspacing=5>n";
    do {

    $day1=$myrow["day1"];
    // i guess your field name is day1.

    $enddate=$myrow["enddate"];
    // i guess your field name is enddate.


    $date_time_array1 = getdate ($day1);
    $start = $date_time_array1[ "weekday,month,mday,year"];

    $date_time_array2 = getdate ($enddate);
    $end = $date_time_array2[ "weekday,month,mday,year"];


    printf("<tr><td valign=top ><b>%s</b> , On <b>$start</b> at <b>%s</b> and ending on <b>$end</b> </td></tr><tr><td valign=top >%s</td></tr><tr><td><b>Address: </b>%s <b>City: </b>%s <b>State: </b>%s</td></tr><tr><td valign=top><b>Contact: </b> %s %s $email $url<BR><BR></td></tr>n", $myrow["event"], $myrow["time"], $myrow["words"], $myrow["address"], $myrow["city"], $myrow["state"], $myrow["contact"], $myrow["phone"]);

    } while ($myrow = mysql_fetch_array($result));
    echo "</table>n";
    } else {
    echo "Sorry, no records were found!";
    }
    ?>
    </center>
    </body>
    </html>


    i think above may help in some way

    ------------------
    SR -
    webshiju.com
    www.jobxyz.com-IT Career Portal
    ezipindia.com--WebStudio


    "The fear of the LORD is the beginning of knowledge..."

    [This message has been edited by Shiju Rajan (edited September 27, 2000).]
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Posts
    61
    Rep Power
    14
    This is getting very embarrassing!

    Yes, 'day1' and 'enddate' are the 2 dates I have in the table (as big int type). I have checked again, both contain the number of seconds from 1-1-1970 until 9-25-2000.

    I copied and pasted the above code from tip to tail. The $start and $end are invalid and do not show up at all. If I replace them with $day1 and $enddate it prints out "969854400". Something in the conversion from the unix time to human time??? The page I am inputting to is at http://opencountry.com/shindigs/addevent1.php3 I am using $day1 = mktime(0,0,0,$smonth,$sday,$syear);
    $enddate = mktime(0,0,0,$emonth,$eday,$eyear); on the input page.

    The output page is at http://64.176.195.97/shindigs/fullcalendartemp.php3 Output may be different - depending on what I am playing with.

    Thanks so much for the help people. I don't know how to repay you except by admiring your skills and passing it on, if I ever learn this stuff.

Similar Threads

  1. adjusting time duration from a drop down menu
    By spyghost in forum HTML Programming
    Replies: 9
    Last Post: March 1st, 2004, 02:05 AM
  2. time in - time out
    By newbiex in forum PHP Development
    Replies: 2
    Last Post: February 9th, 2004, 02:04 AM
  3. Adding time to time
    By bizantium in forum PHP Development
    Replies: 2
    Last Post: February 4th, 2004, 10:43 AM
  4. mySQl for time difference
    By lalitha in forum MySQL Help
    Replies: 1
    Last Post: February 4th, 2004, 02:41 AM
  5. Adding minutes to time and other calcs
    By Jez433 in forum PHP Development
    Replies: 5
    Last Post: January 21st, 2004, 06:00 PM

IMN logo majestic logo threadwatch logo seochat tools logo