Jump to content

Recommended Posts

The time() function returns the current UNIX timestamp, which is the amount of seconds since the Unix Epoch (January 1st, 1970 0:00:00 GMT).

 

The date() function formats a date in the way specified.  As you have used, "w" will return the numerical representation of the day of the week.  By default, the date() function uses the current date and time for the return value, so using date("w") and date("w", time()) will return the exact same thing.  If, however, you wanted to know the day of the week exactly 100 days from now, you could use a combination of the two functions to do so:

 

<?php

$timestamp = time();

$onehundreddays = 60 * 60 * 24 * 100; // The amount of seconds in 100 days

$finaltime = $timestamp + $onehundreddays;

echo "In one hundred days, it will be " . date("l", $finaltime);

?>

 

As you can see, UNIX timestamps become very useful when you want to manipulate dates or calculate spans of time between two dates.  The second parameter of the date() function is entirely optional, and will default to the current timestamp, so putting the current value of time() in it is redundant and unnecessary.

 

I hope that helps your understanding of these two functions.

Link to comment
https://forums.phpfreaks.com/topic/251238-time/#findComment-1288627
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.