PHP

Using PHP CheckDate to validate dates

Using PHP CheckDate to validate dates <?php $month = 2; // February never has 31 days $day = 31; // 31st $year = 2018; // 2018 if (checkdate($month, $day, $year)) { echo “Date is valid”; } else { echo “Date is invalid”; } ?> Output: Date is invalid

PHP Conditional Expression Evaluation With TRUE and FALSE

PHP Conditional Expression Evaluation With TRUE and FALSE Conditional expressions (both if and while statements) are literal or boolean or numeric. Numeric expressions evaluate to true when they are non-zero – zero/0 is false. String expressions evaluate to TRUE when there is nonempty string.  A NULL value is evaluated as false. How do you assign …

PHP Conditional Expression Evaluation With TRUE and FALSE Read More »

Fun with PHP date function – In PHP set your time zone and display date and time in MySQL datetime format.

In PHP set your time zone and display date and time in MySQL datetime format. <?php # ‘YYYY-MM-DD HH:MM:SS is “Y-m-d H:i:s” # set the timezone to LA $fbo=date_default_timezone_set(‘America/Los_Angeles’); # show that the call to set the timezone worked echo “Timezone set? $fbo <br>”; $script_tz = date_default_timezone_get(); # MySQL datetime format $today = date(“Y-m-d H:i:s”); …

Fun with PHP date function – In PHP set your time zone and display date and time in MySQL datetime format. Read More »