WCM Forum

WCM Forum (http://www.wcm.at/forum/index.php)
-   Programmierung (http://www.wcm.at/forum/forumdisplay.php?f=17)
-   -   MYSQL Datumsvergleich (http://www.wcm.at/forum/showthread.php?t=122179)

(V)uh 16.01.2004 16:49

Jetzt wär es interessant welches SQL du verwendest und wo (in welchem programm, umgebung) wenn das mit den # auch nicht funkt. Denn unter Access schreibt man ... SELECT * FROM tabDummy WHERE (((tabDummy.Zeit)>#1/14/2004# And (tabDummy.Zeit)<#1/16/2004#));

Verwendest du die sql anweisung als abfrage oder als parameter beim programmieren ?
Bei manchen systemen muss man die SQL anweisung mit ; abschliessen und bei manchen nicht. Hast du das schon probiert ?

_m3 16.01.2004 18:06

Meine Herren, im Subject steht
"MYSQL Datumsvergleich"

(V)uh 17.01.2004 15:51

Upsi, na ja das fettgedruckte überles ich meist *gg* da denk ich mir immer "zu dick aufgetragen" :D

(V)uh 17.01.2004 16:13

Wenn ich mir sein posting nochmal anschau dann fehlt meiner meinung nach der ";" am ende.
Oder versuch mal SELECT ... WHERE myDatum BETWEEN '2003-08-04' AND '2003-08-07' aber auch mit ";" am ende. Also nicht > oder < sondern BETWEEN.

Vielleicht kannst du für dein problem aber auch eine normale funktion benutzen ... http://www.mysql.com/doc/en/Date_and...functions.html

snowman 17.01.2004 18:58

der fehler ist das falsche datumsformat, bitte glaubs mir.

gruss,
snowman

Dr. Mabuse 19.01.2004 21:38

mein Senf

Code:

SELECT  *  FROM  `veranstaltung`  WHERE `datum`  >=  '2004-01-01' AND  `datum`  <  '2004-01-31'

pc.net 19.01.2004 21:45

bitte strings immer konvertieren ...

http://www.mysql.com/doc/en/Date_and...functions.html
Zitat:

STR_TO_DATE(str,format)
This is the reverse function of the DATE_FORMAT() function. It takes a string str, and a format string format, and returns a DATETIME value. The date, time, or datetime values contained in str should be given in the format indicated by format. For the specifiers that can be used in format, see the table in the DATE_FORMAT() function description. All other characters are just taken verbatim, thus not being interpreted. If str contains an illegal date, time, or datetime value, STR_TO_DATE() returns NULL.
Code:

mysql> SELECT STR_TO_DATE('03.10.2003 09.20', '%d.%m.%Y %H.%i')
        -> 2003-10-03 09:20:00
mysql> SELECT STR_TO_DATE('10rap', '%crap')
        -> 0000-10-00 00:00:00
mysql> SELECT STR_TO_DATE('2003-15-10 00:00:00', '%Y-%m-%d %H:%i:%s')
        -> NULL



snowman 20.01.2004 08:48

warum?

http://www.mysql.com/doc/en/DATETIME.html

Zitat:

You can specify DATETIME, DATE, and TIMESTAMP values using any of a common set of formats:

As a string in either 'YYYY-MM-DD HH:MM:SS' or 'YY-MM-DD HH:MM:SS' format. A ``relaxed'' syntax is allowed--any punctuation character may be used as the delimiter between date parts or time parts. For example, '98-12-31 11:30:45', '98.12.31 11+30+45', '98/12/31 11*30*45', and '98@12@31 11^30^45' are equivalent.

As a string in either 'YYYY-MM-DD' or 'YY-MM-DD' format. A ``relaxed'' syntax is allowed here, too. For example, '98-12-31', '98.12.31', '98/12/31', and '98@12@31' are equivalent.

As a string with no delimiters in either 'YYYYMMDDHHMMSS' or 'YYMMDDHHMMSS' format, provided that the string makes sense as a date. For example, '19970523091528' and '970523091528' are interpreted as '1997-05-23 09:15:28', but '971122129015' is illegal (it has a nonsensical minute part) and becomes '0000-00-00 00:00:00'.

As a string with no delimiters in either 'YYYYMMDD' or 'YYMMDD' format, provided that the string makes sense as a date. For example, '19970523' and '970523' are interpreted as '1997-05-23', but '971332' is illegal (it has nonsensical month and day parts) and becomes '0000-00-00'.

As a number in either YYYYMMDDHHMMSS or YYMMDDHHMMSS format, provided that the number makes sense as a date. For example, 19830905132800 and 830905132800 are interpreted as '1983-09-05 13:28:00'.

As a number in either YYYYMMDD or YYMMDD format, provided that the number makes sense as a date. For example, 19830905 and 830905 are interpreted as '1983-09-05'.

As the result of a function that returns a value that is acceptable in a DATETIME, DATE, or TIMESTAMP context, such as NOW() or CURRENT_DATE.

Illegal DATETIME, DATE, or TIMESTAMP values are converted to the ``zero'' value of the appropriate type ('0000-00-00 00:00:00', '0000-00-00', or 00000000000000).


gruss,
snowman

schera 20.01.2004 08:58

Datumsformat ...
 
Kann mich snowman nur anschliessen, da das Datumsformat falsch ist.

YYYY-MM-DD wäre richtig, also:

SELECT * from Veranstaltung where Datum >= '2004-01-01" AND Datum <= '2004-01-31'

gruss,

schera

darthj 20.01.2004 09:12

Snowman hat recht, am Datumsformat ist es gelegen. Gibt man ein ungültiges Datum an so meint MYSQL 0000-00-00 zum Vergleich nehmen zu müssen. => Datum ist nie kleiner und es kommt nix zurück.

Danke für eure Hilfe.

Eine andere Kurze Frage noch. Gibt es in PHP eine Möglichkeit die Elemente eines Arrays durch die Elemente eines anderen Arrays zu dividieren oder muss man das händisch machen?

LG
Jürgen


Alle Zeitangaben in WEZ +2. Es ist jetzt 15:41 Uhr.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
© 2009 FSL Verlag