Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Random Yesterday's Date

  • This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #173414
    intodesign
    Participant

    Can someone help me please,
    How can I echo a random date of the day before, something like that:

    2014-06-21 22:29:03

    #173420
    intodesign
    Participant

    I mean the hour should be random

    #173422
    Paulie_D
    Member

    OK…I’m confused.

    What is it you want?

    A random hour of a specified date?

    A random hour of a random date?

    A specified hour of a random date

    Something else?

    #173437
    __
    Participant

    If this is not what you’re looking for, you’ll need to explain further.

    /**
     * prints a date/time based on a random timestamp from the last 24 hours
     *
     * @param int $t      starting timestamp (defaults to "now")
     * @param string $f   date/time formatting string {@see php.net/date}
     * @throws E_WARNING  if no default timezone is set
     * @return string     a date/time string on success
     */
    function random_datetime_last_day( $t=null,$f=null ){
      $t = $t?: time();
      $f = $f?: "Y-m-d H:i:s";
      return date( $f,rand( ($t-(60*60*24)),$t ) );
    }
    
    // set timezone as desired
    date_default_timezone_set('UTC');
    
    // call function
    echo random_datetime_last_day();
    
Viewing 4 posts - 1 through 4 (of 4 total)
  • The forum ‘Back End’ is closed to new topics and replies.