Bazrazmataz
04-15-2004, 10:07 AM
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
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