Good day. There is a table of the form

|id| activ | dateTime | ------------------------------ |1 | no-activ | 2012-01-13 01:06:50 | |2 | activ | 2012-01-13 01:06:50 | |3 | activ | 2012-01-13 01:06:50 | |4 | no-activ | 2012-01-13 01:07:50 | 

Now 2012-01-13 01:07:00. It is necessary to sort all entries that are less than now and activ = 'activ' and output all id . I do this:

 "SELECT COUNT(id) FROM `activ` WHERE `dateTime`<LOCALTIME() AND `activ`='activ';" 

and displays the number of records suitable for the parameters. But at the same time, if I ask a query like this:

 "SELECT `id` FROM `activ` WHERE `dateTime`<LOCALTIME() AND `activ`='activ';" 

then nothing comes. Where is the mistake???

    2 answers 2

    Sul according to the first table in the query mistakenly uses a non-existent dateTime field.

    Need to:

     SELECT COUNT(id) FROM `activ` WHERE `date`<LOCALTIME() AND `activ`='activ' 

    AND:

     SELECT `id` FROM `activ` WHERE `date`<LOCALTIME() AND `activ`='activ' 
    • one
      There is no field in the dataTime table, but here something forgot to assign "Time". - KARTOH

    Store the date in timestamp, by it and sort

     int mktime ([int hour [, int minute [, int second [, int month [, int day [, int year [, int is_dst]]]]]]]) 

    Getting the current date time()

    To return back to its usual form, use strftime('%d.%m.%Y',дата в timestamp);