Jump to content

PHP homework


Sherlock_Skywalker

Recommended Posts

I got stuck with one question of my php homework. Hope u guys can help and advise the step by step codings.

About the subject, There is no PHP that can be selected in Course Hero

 

please see below question

 

Question 1:

 

Following is the implementation of date time function in php:

 

<?php

$dateString = date("Y/m/d h:i:s"); //current date with format

echo "Today is $dateString<br>";

//mktime(hour,minute,second,month,day,year)

$mydate = mktime(13, 34, 46, 12, 24, 2017);

$dateString = date("Y/m/d h:i:sa", $mydate);

echo "My Date is $dateString<br>";

$errordate = mktime(25,25,-1,15,32,1900);

$dateString = date("Y/m/d h:i:sa", $errordate);

echo "Error Date is $dateString<br>";

?>

 

 

To get simple date, you have one of the parameters format in date(). Few characters need to be specified within the parameter.

 

'd' for the day of month (1-31)

'm' for month number (1-12)

'y' stands for year(it should be 4 digit)

'h' shows 12 hour format (01 - 12)

'I' shows minutes with zeroes(00-59)

's' denotes seconds (00-59)

'a' denotes am or pm.

 

The mktime() function is an inbuilt function in PHP which is used to return the Unix timestamp for a date.

 

The timestamp returns a long integer containing the number of seconds between the Unix Epoch (January 1, 1970, 00:00:00 GMT) and the time specified.

 

Without the parameter, mktime() will return the current timestamp of your server.

 

However, you will find that there will have an error on display the date or time if users pass some value which do not follow the rule of date and time, e.g. month is 13.

 

You are required to write new function with name validDate($month, $day, $year) which will

return an error message "Invalid parameter(s) for the date!" if passing an invalid parameters to this function.

If no error found, return the date in string with "Y/m/d" format.

 

Example codes:

 

<?php

$dateString = validDate(13,32,1969);

echo "My Date is $dateString<br>";

$dateString = validDate(12,31,2018);

echo "My Date is $dateString<br>";

...

?>

Link to comment
Share on other sites

I'm not even sure I understand the question, BUT it seems from

Quote

return an error message "Invalid parameter(s) for the date!" if passing an invalid parameters to this function.

that you need to write a function that will analyze the calendar entries.

The depth to which you go is up to you, but for starters you would need to determine which months have 30 days and which have 31. 

Just as there would be no acceptable MONTHS > 12, there is also no date of September 31 or October 32.

Of course, February and Leap Years will be the biggest challenge.

My solution: Tell the instructor that all inputs will come from drop-down menus and go get a coffee.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.