date()
itself is only for formatting, but it accepts a second parameter.
date("F j, Y", time() - 60 * 60 * 24);
To keep it simple I just subtract 24 hours from the unix timestamp.
A modern oop-approach is using DateTime
$date = new DateTime(); $date->sub(new DateInterval('P1D')); echo $date->format('F j, Y') . "\n";
Or in your case (more readable/obvious)
$date = new DateTime(); $date->add(DateInterval::createFromDateString('yesterday')); echo $date->format('F j, Y') . "\n";
(Because DateInterval
is negative here, we must add()
it here)
See also: DateTime::sub()
and DateInterval
Related Posts:
- Converting string to Date and DateTime
- Compare given date with today
- How to reformat date in PHP?
- How to find the date of a day of the week from a date using PHP?
- Convert a date format in PHP
- How to find the last day of the month from date?
- how to get date of yesterday using php?
- What is the MM/DD/YYYY regular expression and how do I use it in php?
- Subtracting days, months or years from date using php
- How to get time difference in minutes in PHP
- A non well formed numeric value encountered
- Adding days to $Date in PHP
- What’s the net::ERR_HTTP2_PROTOCOL_ERROR about?
- PHP “or” Syntax
- S_SESSION variable (user role) not recognised
- Is SAJAX dead? What to replace with?
- Invalid column count in CSV input on line 1 Error
- How to check if a string starts with a specified string?
- mysqli_real_connect(): (HY000/2002): No such file or directory
- What is difference between PHP cli and PHP cgi?
- $wpdb->update or $wpdb->insert results in slashes being added in front of quotes
- Why use $_SERVER[‘PHP_SELF’] instead of “”
- phpMyAdmin: secret passphrase?
- Are there dictionaries in php?
- laravel updateOrCreate method
- How to listen messageSent event in laravel 5.5
- Make a HTTPS request through PHP and get response
- How to insert an item at the beginning of an array in PHP?
- PHP Deprecated: Methods with the same name
- How do the PHP equality (== double equals) and identity (=== triple equals) comparison operators differ?
- How do I pass JavaScript variables to PHP?
- Call to undefined function curl_init().?
- How to verify password against database?
- what is a good method to sanitize the whole $_POST array in php?
- pdo – Call to a member function prepare() on a non-object
- Multi-line strings in PHP
- Commands out of sync; you can’t run this command now
- cURL error 60: SSL certificate: unable to get local issuer certificate
- Replace spaces with a dash in a URL
- Are PDO prepared statements sufficient to prevent SQL injection?
- Message: Trying to access array offset on value of type null [duplicate]
- SSL error SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
- retrieve data from db and display it in table in php .. see this code whats wrong with it?
- PDO closing connection
- “Valid CSRF Token Required” in Osticket After login?
- Count how many files in directory PHP
- Simple PHP calculator
- Convert from MySQL datetime to another format with PHP
- php foreach with multidimensional array
- header location not working in my php code
- PHP Error: Function name must be a string
- Uncaught Error: Call to undefined function mysql_escape_string()
- Warning: mysqli_query() expects at least 2 parameters, 1 given. What? [duplicate]
- PHP cURL custom headers
- Parsing domain from a URL
- PHP class not found but it’s included
- How to fix the session_register() deprecated issue?
- Laravel 5 MethodNotAllowedHttpException in RouteCollection.php line 201:
- How to convert string to boolean php
- PHP “&” operator
- Are There Any Cron Jobs Alternative?
- What is ?
- Connection reset by peer: mod_fcgid: error reading data from FastCGI server
- How to import csv file in PHP?
- What is the syntax for accessing PHP object properties?
- * failed to open vchiq instance
- Mysql where id is in array
- How to extract and access data from JSON with PHP?
- The character encoding of the HTML document was not declared
- Warning “Do not Access Superglobal $_POST Array Directly” on Netbeans 7.4 for PHP
- Notice: Undefined offset: 0 in
- How to Sort a Multi-dimensional Array by Value
- How to write a link like which link to the same page in PHP?
- Call a REST API in PHP
- Fatal error: Call to a member function query() on null
- How can I write php code in notepad++?
- PHP + JQuery – How to use these two together? Please see my example
- How to run a PHP function from an HTML form?
- Data extraction from /Filter /FlateDecode PDF stream in PHP
- How to use data-saferedirecturl in a tag in PHP?
- How to insert TIMESTAMP into my MySQL table?
- Remove warning messages in PHP
- Clear cache in Symfony: `cache:clear` or `rm -rf`?
- Is there any difference between aes-128-cbc and aes-128 encryption?
- create php live clock
- Converting a UNIX Timestamp to Formatted Date String
- PHP Call to undefined function
- Formatting a number with leading zeros in PHP
- POST an array from an HTML form without javascript
- WordPress get_template_directory_uri() not returning https and only return http
- WP_Query meta_query results date by date
- Way to display “Yesterday”, “Today”
- display month in french in wordpress/php?
- Get date numerical and separate?
- How to manually change current date to post date in frontend?
- Get posts from year from URL
- Can’t add to time? [closed]
- Grouping posts by date
- Get month and day from a Date Picker custom field
- Convert custom field date format to “WordPress default”