Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,880 questions

51,806 answers

573 users

How to define constants to convert time sizes to number of seconds with PHP

1 Answer

0 votes
define('MINUTE_IN_SECONDS', 60);
define('HOUR_IN_SECONDS', 60 * MINUTE_IN_SECONDS);
define('DAY_IN_SECONDS', 24 * HOUR_IN_SECONDS);
define('WEEK_IN_SECONDS', 7 * DAY_IN_SECONDS);
define('MONTH_IN_SECONDS', 30 * DAY_IN_SECONDS); // approximate value
define('YEAR_IN_SECONDS', 365 * DAY_IN_SECONDS); // approximate value

	
echo "1 MINUTE = " . number_format(MINUTE_IN_SECONDS, 0, ',') . " seconds \n";
echo "1 HOUR = " . number_format(HOUR_IN_SECONDS, 0, ',') . " seconds \n";
echo "1 DAY = " . number_format(DAY_IN_SECONDS, 0, ',') . " seconds \n";
echo "1 WEEK = " . number_format(WEEK_IN_SECONDS, 0, ',') . " seconds \n";
echo "1 MONTH = " . number_format(MONTH_IN_SECONDS, 0, ',') . " seconds \n";
echo "1 YEAR = " . number_format(YEAR_IN_SECONDS, 0, ',') . " seconds \n";
 
 
 
 
/*
run:
 
1 MINUTE = 60 seconds 
1 HOUR = 3,600 seconds 
1 DAY = 86,400 seconds 
1 WEEK = 604,800 seconds 
1 MONTH = 2,592,000 seconds 
1 YEAR = 31,536,000 seconds 
 
*/
 

 



answered Jul 9, 2023 by avibootz

Related questions

3 answers 130 views
2 answers 104 views
1 answer 57 views
2 answers 191 views
...