Toon posts:

[php/mysql] timestamp...

Pagina: 1
Acties:

Verwijderd

Topicstarter
Ik heb in het forum gezocht, dingen geprobeert, niets hielp... :(

Mijn datums staan zo in de database:

mm.dd.yyyy

Ik wil dat m'n query alles selecteerd tussen 2 datums.
Ik heb van alles geprobeert, UNIX_TIMESTAMP, DATE_FORMAT, mktime functie, strtotime.. niets hielp :(
Is dit mogenlijk?
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?

$month = mktime (0,0,0,date("m")-1,date("d"),date("Y"));
$month = date("m.d.Y", $month);

$today = mktime (0,0,0,date("m"),date("d"),date("Y"));
$today = date("m.d.Y", $today);

$query = mysql_query("SELECT
                DISTINCT(groupname),
                COUNT(title) AS releasecount
                FROM releases
                WHERE type='$section'
                AND date > '$month'
                AND date < '$today'
                GROUP BY groupname
                ORDER BY releasecount DESC, groupname ASC
                LIMIT 20");
?>

  • chuxiej
  • Registratie: Februari 2001
  • Laatst online: 13-07-2020
SELECT * FROM bla WHERE datum BETWEEN 'timestamp1' AND 'timestamp2'? zoiets?

www.dannyhiemstra.nl


Verwijderd

Topicstarter
Op dinsdag 30 april 2002 04:19 schreef FireFoxx het volgende:
SELECT * FROM bla WHERE datum BETWEEN 'timestamp1' AND 'timestamp2'? zoiets?
BETWEEN??

  • chuxiej
  • Registratie: Februari 2001
  • Laatst online: 13-07-2020
ja lijkt me wel zo handig :*
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
expr BETWEEN min AND max 
If expr is greater than or equal to min and expr is less than or equal to max, BETWEEN returns 1, otherwise it returns 0. This is equivalent to the expression (min <= expr AND expr <= max) if all the arguments are of the same type. The first argument (expr) determines how the comparison is performed as follows: 
If expr is a TIMESTAMP, DATE, or DATETIME column, MIN() and MAX() are formatted to the same format if they are constants. 
If expr is a case-insensitive string expression, a case-insensitive string comparison is done. 
If expr is a case-sensitive string expression, a case-sensitive string comparison is done. 
If expr is an integer expression, an integer comparison is done. 
Otherwise, a floating-point (real) comparison is done. 
mysql> SELECT 1 BETWEEN 2 AND 3;
      -> 0
mysql> SELECT 'b' BETWEEN 'a' AND 'c';
      -> 1
mysql> SELECT 2 BETWEEN 2 AND '3';
      -> 1
mysql> SELECT 2 BETWEEN 2 AND 'x-3';
      -> 0

http://www.mysql.com/doc/C/o/Comparison_Operators.html

www.dannyhiemstra.nl


Verwijderd

Topicstarter
Heh, nooit geweten :)
Ik zal het proberen, thnx

Verwijderd

Topicstarter
code:
1
2
3
4
5
6
7
8
9
10
11
      $query = mysql_query("SELECT
                    DISTINCT(groupname),
                    COUNT(title) AS releasecount
                    FROM gotdupe_releases
                    WHERE type='$section'
                    AND date
                    BETWEEN UNIX_TIMESTAMP('$month')
                    AND UNIX_TIMESTAMP('$today')
                    GROUP BY groupname
                    ORDER BY releasecount DESC, groupname ASC
                    LIMIT 20");

Dat werkt dus ook niet :(
Ook niet zonder unix_timestamp. Hoe kan ik er voor zorgen dat UNIX_TIMESTAMP werkt met het formaat wat ik gebruik? mm.dd.yyyy?

  • SJR
  • Registratie: Januari 2000
  • Laatst online: 15-02 13:58

SJR

Dat datum veld in de database is gewoon een (var)char zeker? Dan wordt het moeilijk, want dan ga je strings vergelijken. Tenzij mysql misschien een functie heeft om een timestamp te maken van zo'n datum.
Enniewee, ik zet m'n data altijd als timestamp (int) in de database, volgens mij werkt dat veel makkelijker.
Pagina: 1