Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-15-2004, 10:07 AM   PM User | #1
Bazrazmataz
New Coder

 
Join Date: Apr 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Bazrazmataz is an unknown quantity at this point
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
Bazrazmataz is offline   Reply With Quote
Old 04-15-2004, 10:37 AM   PM User | #2
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,890
Thanks: 5
Thanked 79 Times in 78 Posts
firepages will become famous soon enough
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)
firepages is offline   Reply With Quote
Old 04-15-2004, 02:32 PM   PM User | #3
Bazrazmataz
New Coder

 
Join Date: Apr 2004
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Bazrazmataz is an unknown quantity at this point
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 !!!
Bazrazmataz is offline   Reply With Quote
Old 04-15-2004, 02:50 PM   PM User | #4
firepages
Super Moderator


 
Join Date: May 2002
Location: Perth Australia
Posts: 3,890
Thanks: 5
Thanked 79 Times in 78 Posts
firepages will become famous soon enough
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)
firepages is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:40 PM.


Advertisement
Log in to turn off these ads.