Jump to content
php.lv forumi

seciba pec datuma


Mikijs

Recommended Posts

Sveiki, man ir aptuveni sada sql tabula

 

id  |  datums  |  laiks  |  nosaukums
--------------------------------------------
 1  |  2008-13-07  |  11:10  |  Sports
 2  |  2008-15-08  |  18:05  |  Izklaide
 3  |  2008-28-11  |  23:11  |  Jaunumi
 4  |  2009-08-03  |  23:11  |  Jaunumi
 5  |  2009-02-12  |  23:11  |  Jaunumi

 

Ka lai es sorteju pec datuma ? (YY-mm-dd) ?

izmantojo "select * from tabula order by date desc" ... nesorte ka vaig..

 

kolona "date" arii ir type:date

Link to comment
Share on other sites

Tāpēc, ka datumu vajag glabāt yyyy-mm-dd formā, tad sortēs pareizi.

Var jau manuāli pārveidot datumu no yyyy-dd-mm uz yyyy-mm-dd ar MySQL datumu funkcijām tajā order by XXX daļā. Bet tad būs liela bremze.

 

Nez vispār kā tu DATE tipa kolonna esi dabūjis datus yyyy-dd-mm formā?

DATE

 

A date. The supported range is '1000-01-01' to '9999-12-31'. MySQL displays DATE values in 'YYYY-MM-DD' format, but allows assignment of values to DATE columns using either strings or numbers.

(iz http://dev.mysql.com/doc/refman/5.0/en/dat...-overview.html)

Link to comment
Share on other sites

andrisp :D baig sudigi sasorte

 

select * from table where user='$iMEMBER[id]' order by date

 

Sasorteja sita

Datums | Laiks

2008-07-27 08:31

2008-07-23 20:30

2008-07-23 22:30

2008-07-23 22:30

2008-07-24 20:40

2008-07-24 20:40

2008-07-24 20:40

2008-07-27 12:31

2008-07-29 11:30

2008-08-27 20:03

2008-09-23 18:29

2008-10-26 23:30

 

 

gandriz pareizi tikai ka es skatos tad 1 laucinjs ir augstaks datums neka 2 :)

 

andrisp :D vienmer kko taisu

Link to comment
Share on other sites

CREATE TABLE IF NOT EXISTS `notify` (
 `id` int(255) unsigned NOT NULL auto_increment,
 `user` int(255) NOT NULL,
 `time` varchar(10) NOT NULL,
 `date` varchar(10) NOT NULL,
 `name` varchar(255) NOT NULL,
 PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=6 ;

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...