I want to show distinct Year in my currenttime database field which is actually timestamp by structure.
I want to show years like :-
2011 and so on .

but the problem , the result of my query gives me
10-09-2013 12:11:17
10-09-2012 12:11:14
10-09-2011 12:11:17
which i want as shown above i .e 2013,2012,2011 and so on....

<?php  echo $currentyear= date("Y");?>
$query_rs_dyear = "Select DISTINCT complaint.currenttime from complaint WHERE complaint.currenttime!='$currentyear' order by '$currentyear' desc";

Recommended Answers

All 8 Replies

As I understand it your query does what it should (orders correctly). But displayed date has too much useless info you need only the year.
You need this: $mysql_return = '10-09-2011 12:11:17';

$mysql_return = date_parse($mysql_return);
echo $mysql_return['year'];


Member Avatar

Just so that you're aware. From the php manual:

Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed.

To avoid potential ambiguity, it's best to use ISO 8601 (YYYY-MM-DD) dates or DateTime::createFromFormat() when possible.

10-09-2011 is ambiguous as hell, until you apply the above, in which case php reads this as 10th Sept 2011 (Europe) and not 9th October 2011 (USA), due to the '-' separator.

Of course, this will make no difference to the year, but could have an affect other functions - you are storing the whole date/time for some purpose I would imagine.

Dear fenixZ,
what i need from the above mentioned my problem is to extract only
instead of
10-09-2013 12:11:17
10-09-2012 12:11:14
10-09-2011 12:11:17
Hope so, uve got my point. !
discussion will be appreciated.

please help me i need a php code in which displays my computer's date and time,
also i need a code in which i will log-in using a biometric system also in php. this is for my thesis program thanks, e-mail me mafiachingkangz@gmail.com

Member Avatar

> what i need from the above mentioned my problem is to extract only

It's what he gave you. Have you at least tried it??

@ardav Thanks for your comment I really did not think about time zones and separators in that case. But they are importnat for example at the end of the year.
That's why I gave the reference so he can read more on the subject.

@khushhappy I understood you correctly but you have to read slower and try the code I wrote for you.

Dear fenixZ,
Got the point and got the result as well ! :)
Thanks for participation .

(Khushnaam Ali)
Ministry of Commerce,Secretariat.

Member Avatar

Please mark as solved (link below the edit box)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.