Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Apr 2004
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Begginer Date Probs

    Hi

    Ive got to the date section of php in my book im working through but cannot seem to get any of the code to work without either a jumble of random numbers appearing or error messages.

    Bellow i have typed in word for word the parts of the book im stuck on.

    You can assign a timestamp with the current date and time to a variable with the following statements:
    $today = time();

    You can store a specific date and time as a timestamp using the function mktim. The Format is:
    $importantDate = mktime (h,m,s,mo,d,y)

    where h is hours, m is minutes, s is seconds, mo is months, d is days, y is years. For instance you would store
    the date January 15 2002 using the following statement:
    $importantDate = mktime(0,0,0,1,15,2002);

    if you wanted to know how long ago $importantDate was you could subtract it from $today For instance:
    $timeSpan = $today - $importantDate;

    This gives you the number of seconds between the important date and today or use the statement:
    $timeSpan = (($today - $importantDate))/60/60

    Dates and times must be formatted in the correct MySQL format to store them in your database. PHP functions can
    be used for formatting. For instance, you can format todays date in MySQL format using the statement:
    &today = ("yyyy-m-d");

    Cheers for any help

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    well the book is wrong here ....
    PHP Code:
    <?
    $timeSpan 
    = (($today $importantDate))/60/60;
    ?>
    should be
    <?
    $timeSpan 
    $today $importantDate;
    ?>
    to give the time in seconds, time() && mktime() return the number of seconds since the beginning of the unix epoch (Jan 1st 1970), so all date calculations on variables returned from time() or mktime() are already in seconds ... e.g. you would therefore convert to hours via ..

    PHP Code:
    <?
    $timeSpanInHours 
    = ($today $importantDate) * 3600 ;
    ?>
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    New Coder
    Join Date
    Apr 2004
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The Damm book seems to have a lot of errors in it!! i am only up to pg 133 and already ive had tonnes of mistakes! i email the publishers but they ignore me !!!

  • #4
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,108
    Thanks
    11
    Thanked 101 Times in 99 Posts
    I honestly find the PHP manual the best 'book' , the user notes are invaluable , you can download the manual (notes and all) in a variety of formats ... (windows CHM recommended) http://www.php.net/download-docs.php
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)


  •  

    Posting Permissions

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