Warrior Forum - The #1 Digital Marketing Forum & Marketplace

Warrior Forum - The #1 Digital Marketing Forum & Marketplace (https://www.warriorforum.com/)
-   Programming (https://www.warriorforum.com/programming/)
-   -   How do I set default value of function parameter as today's date? (https://www.warriorforum.com/programming/543147-how-do-i-set-default-value-function-parameter-todays-date.html)

jalicia18 17th February 2012 01:10 AM

How do I set default value of function parameter as today's date?
 
How do I set default value of function parameter as today's date?

I tried:
function funcName($today=date('Y-m-d')) {do something}

Throws me this error:
Parse error: syntax error, unexpected '(', expecting ')'

Thanks.

ussher 17th February 2012 03:20 AM

Re: How do I set default value of function parameter as today's date?
 
try:
function funcName($today=false) {
if(!$today){
$today = date('Y-m-d');
}

//do something

}

guava 17th February 2012 05:55 AM

Re: How do I set default value of function parameter as today's date?
 
Just checking. Is this PHP?

guava 17th February 2012 05:57 AM

Re: How do I set default value of function parameter as today's date?
 
Is this PHP?

KirkMcD 17th February 2012 06:16 AM

Re: How do I set default value of function parameter as today's date?
 
If this is for PHP
try:

define('TODAY', date('Y-m-d'));
function funcName($today=TODAY);


All times are GMT -6. The time now is 06:33 PM.