Post by David Sanchez » Tue Jan 07, 2014 1:47 am

Hello!

I have a question, I tried to search but didn't find anything about this (I'm continuing with the search). I would like to sort the products, costumers, whatever by using a date, but instead of just sorting using the absolute value (e.g: 1970/10/10 1970/10/20 2014/1/1) i will like to short it by month, or by day...

If you have any idea or suggestions please share!

P.S: I dont need the solution, I like to find out things by myself, but if someone can give me a hint I will appreciate!

THanks >)

Visit our Store http://www.Alzoco.com for more info


Newbie

Posts

Joined
Tue Dec 10, 2013 11:58 pm
Location - Beijing, China

Post by billynoah » Sun Jan 12, 2014 4:03 pm

you could use SUBSTRING_INDEX in your query. for instance to sort by month of date_added:

order by SUBSTRING_INDEX(date_added, '-', -2);

or day:

order by SUBSTRING_INDEX(date_added, '-', -1);

or hour:

SUBSTRING_INDEX(date_added, ' ', -1);

etc...

Image


Active Member

Posts

Joined
Tue Jan 15, 2013 12:46 pm
Who is online

Users browsing this forum: No registered users and 17 guests