sungpeng Posted November 16, 2011 Share Posted November 16, 2011 $timestamp = time(); echo "$timestamp"; result "1321422809"; What does 1321422809 stand for? Quote Link to comment https://forums.phpfreaks.com/topic/251238-time/ Share on other sites More sharing options...
sungpeng Posted November 16, 2011 Author Share Posted November 16, 2011 I can't understand the function of $timestamp in date also date("w",$timestamp=time()); Quote Link to comment https://forums.phpfreaks.com/topic/251238-time/#findComment-1288607 Share on other sites More sharing options...
Drummin Posted November 16, 2011 Share Posted November 16, 2011 From what I understand, a timestamp is the number of seconds from January 1, 1970 at 00:00. I personally don't find it useful but I sure there are places for it. I always use date() as in date("Y/m/d");. See http://php.net/manual/en/function.date.php for date options. Quote Link to comment https://forums.phpfreaks.com/topic/251238-time/#findComment-1288610 Share on other sites More sharing options...
sungpeng Posted November 16, 2011 Author Share Posted November 16, 2011 date("w",$timestamp=time()); Is it with or without $timestamp make no different? date("w"); Quote Link to comment https://forums.phpfreaks.com/topic/251238-time/#findComment-1288617 Share on other sites More sharing options...
cypher86 Posted November 16, 2011 Share Posted November 16, 2011 its simply the unix time and it's really useful when you have to deal with operations on dates. Quote Link to comment https://forums.phpfreaks.com/topic/251238-time/#findComment-1288619 Share on other sites More sharing options...
sungpeng Posted November 16, 2011 Author Share Posted November 16, 2011 $testing=date("w",$timestamp=time()); echo "$testing"; I see no different in output in this 2 codes. So can't understand why people need to use $timestamp in coding date. $testing=date("w"); echo "$testing"; Quote Link to comment https://forums.phpfreaks.com/topic/251238-time/#findComment-1288620 Share on other sites More sharing options...
Drummin Posted November 16, 2011 Share Posted November 16, 2011 Did you see the link I posted above? What date format are you looking for? The "w" gives you the numeric representation of the day of the week 0 (for Sunday) through 6 (for Saturday) when used with date(); Quote Link to comment https://forums.phpfreaks.com/topic/251238-time/#findComment-1288622 Share on other sites More sharing options...
nethnet Posted November 16, 2011 Share Posted November 16, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/251238-time/#findComment-1288627 Share on other sites More sharing options...
sungpeng Posted November 16, 2011 Author Share Posted November 16, 2011 Thank nethnet Quote Link to comment https://forums.phpfreaks.com/topic/251238-time/#findComment-1288637 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.