Vince889 Posted September 17, 2011 Share Posted September 17, 2011 Hey guys, Why exactly do people use multiplication when calculating time? Like when setting cookies, timeouts or something that requires second-based definitions. For example, some do: $thirty_days = time()+60*60*24*30; As opposed to what I do: $thirty_days = time()+2592000; Why do they do that? Does it help them calculate it without a calculator? Make it easier to manage/adjust in the future? Personal preference? These are the only possible explanations I can think of. This has been bugging me for a while...am I doing something wrong? Quote Link to comment https://forums.phpfreaks.com/topic/247340-quick-probably-simple-question-about-coding-practice/ Share on other sites More sharing options...
jcbones Posted September 17, 2011 Share Posted September 17, 2011 I think it is laziness. I do the same as you do. It isn't hard to remember that there are 86400 seconds per day, yet I see people all the time do 60*60*24. Quote Link to comment https://forums.phpfreaks.com/topic/247340-quick-probably-simple-question-about-coding-practice/#findComment-1270256 Share on other sites More sharing options...
voip03 Posted September 17, 2011 Share Posted September 17, 2011 $thirty_days = time()+60*60*24*30; The code is self explanatory. It is good practice to write a simple and secure code. Quote Link to comment https://forums.phpfreaks.com/topic/247340-quick-probably-simple-question-about-coding-practice/#findComment-1270270 Share on other sites More sharing options...
gurpreet94 Posted September 17, 2011 Share Posted September 17, 2011 I use this method: $thirty_days = time()+60*60*24*30; Simply because it's easier to change the number of days or whatever you want, or spot any errors in time (for example I might put an extra 0 your way) Quote Link to comment https://forums.phpfreaks.com/topic/247340-quick-probably-simple-question-about-coding-practice/#findComment-1270271 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.