$dateString = '2022-03-14'; $timestamp = CRM_Utils_Date::unformat($dateString, 'Ymd'); echo $timestamp; // output: 1647292800 (corresponding to March 14, 2022)
$dateString = '14th March 2022'; $timestamp = CRM_Utils_Date::unformat($dateString, 'dS F Y'); echo $timestamp; // output: 1647292800 (corresponding to March 14, 2022)In both of these examples, the unformat() method is called on the CRM_Utils_Date class, passing in a string date representation and a format string. The format string specifies the exact format of the date string provided, which allows the unformat() method to parse it correctly. The CRM_Utils_Date class is part of the CiviCRM package library, which is a widely-used PHP-based CRM system.