/    Sign up×
Community /Pin to ProfileBookmark

fetch current date record of dd/mm/yyyy format in php mysql

Hello experts,

I am stuck with an query. Actually i want to fetch current date records from my database and the below code probably fetches all my current date records. But it fetches in d/m/y (26/01/14) format but i need in dd/mm/yyyy (26/01/2014) .
Below is the code which gives output as d/m/y format:

[code=php]
<?php
ini_set( “display_errors”, 0);
$con=mysqli_connect(“localhost”,”root”,””,”test”);
// Check connection
if (mysqli_connect_errno())
{
echo “Failed to connect to MySQL: ” . mysqli_connect_error();
}
$today = date(‘d-m-y’);
$result = mysqli_query($con,”SELECT * FROM Persons WHERE DATE(startdate) = ‘$today'”);

echo “<table border=’1’>
<tr>
<th>id</th>
<th>name</th>
<th>Startdate</th>
<th>Details</th>

</tr>”;

while($row = mysqli_fetch_array($result))
{
echo “<tr>”;
echo “<td>” . $row[‘id’] . “</td>”;
echo “<td>” . $row[‘name’] . “</td>”;
echo “<td>” . $row[‘startdate’] . “</td>”;
echo “<td>” . $row[‘details’] . “</td>”;
echo “</tr>”;
}
echo “</table>”;

mysqli_close($con);
?>

[/code]

I tried with the above code and also tried to change the date format i.e :
$today = date(‘d-m-y’);
to $today = date(‘dd-mm-yyyy’);

I am not understanding what i am missing. Just need some help in this. Any help is appreciated.

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmJan 26.2014 — Have you tried displaying the result of your DATE function from your query statement to see what that value looks like? AFAIK, dates from a MySQL db are in the form yyyy-mm-dd which you can alter by using the DATE_FORMAT (?) function, not DATE. I think in your case you can alter either the query's function or the date functions format to make them align
×

Success!

Help @jackgoddy123 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...