T. Khani
T. Khani

Reputation: 13

Passing variable data to string date

i want to pass variable in date function. it works while passing only one variable but if i pass two variable one for month and other for year then it does not work Please resolve

<?php
 $m = 'June';
 $y = '2011';
 echo $cutoff = date('m-d-Y', strtotime( $m . '01' . ' 2011'));
 echo '<br>';
 echo $nono = date('m-t-Y', strtotime( $m . '01' . $y)); 
?> 

Upvotes: 1

Views: 126

Answers (3)

Parth Chavda
Parth Chavda

Reputation: 1829

change

echo $nono = date('m-t-Y', strtotime( $m . '01' . $y));

to

echo $nono = date('m-t-Y', strtotime( $m . ' 01 ' . $y)); 

Upvotes: 0

Nirnae
Nirnae

Reputation: 1345

You have an error in your parameters, you need to add a space between day and year :

Not working

 echo $nono = date('m-t-Y', strtotime( $m . '01' . $y)); 

Working :

 echo $nono = date('m-t-Y', strtotime( $m . '01 ' . $y)); 

Upvotes: 0

otezz
otezz

Reputation: 1272

You might want to add space to your parameter

echo $nono = date('m-t-Y', strtotime( $m . ' 01 ' . $y));

Upvotes: 2

Related Questions