Jump to content

Sherlock_Skywalker

New Members
  • Posts

    1
  • Joined

  • Last visited

Everything posted by Sherlock_Skywalker

  1. 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>"; ... ?>
×
×
  • 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.