How can I convert a date from a database into a Unix timestamp for date calculations in PHP?

To convert a date from a database into a Unix timestamp for date calculations in PHP, you can use the strtotime() function to convert the date string into a timestamp. This will allow you to perform various date calculations and comparisons easily.

// Assuming $dateFromDatabase is the date retrieved from the database
$dateFromDatabase = "2022-01-15";

// Convert the date into a Unix timestamp
$timestamp = strtotime($dateFromDatabase);

// Now you can perform date calculations using the timestamp
echo date("Y-m-d", $timestamp); // Output: 2022-01-15