Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change format using variable 1

Status
Not open for further replies.

keepingbusy

Programmer
Apr 9, 2000
1,470
GB

Hi

Part of my code has a line containing a variable which is a date:
Code:
echo "<td ><strong>Date posted:</strong></td><td>".$listing['[b]PostDate[/b]']."</td>";
PostDate is a date stored in a format like yyyy-mm-dd

I have found this:
Code:
$dt = date_create_from_format 'd/m/Y', "02/03/2008" );
echo $dt->format( 'd/m/Y' ), "\n";
which I understand will change the date format to dd-mm-yyyy

This is ok if you use the date "02/03/2008"

What I want to use is the variable PostDate instead of "02/03/2008"

I have tried different combinations to make the variable date PostDate show but I keep getting errors.

Please can anyone assist?

Thank you
 
Code:
echo date ("d-m-Y', strtotime($listing['PostDate']));

 

Hi jpadie

Very quick response, thank you

However, the following appeared:
Code:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /homepages/XX/XXXXXXXXXX/XXXXXX/XXXXXXXX/memberindex.php on line 85
I notice also, that part of the original code is not part of the code you posted.

My code:
Code:
echo "<td ><strong>Date posted:</strong></td><td>".$listing['PostDate']."</td>";
Your code:
Code:
echo date ("d-m-Y', strtotime($listing['PostDate']));
Any suggestions?

Thank you
 
i mismatched the quotes on the first argument.
and i assumed that you could do the formatting ok.

Code:
echo "<td><strong>Date posted</strong</td><td>".date ('d-m-Y', strtotime($listing['PostDate'])) . "</td>";
 
echo "Just so you know you don't have to " . $saysomething['inphp'] . " and continue with a sentence. You can {$sayanother['thing']} and keep on truckin.
 
robbiesmith79

you do not need the curly braces either in this case. you can include an array element within a double quoted string thus:
Code:
echo "I am an $array[element]"; //note the absence of quotes around the element key
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top