Avatar billede vandhunden Nybegynder
02. november 2001 - 17:20 Der er 2 kommentarer og
3 løsninger

Dato i SQL-sætning

Jeg har et problem med en (acces)database hvor jeg på en asp-side vil udtrække alle poster som ikke er af ældre dato. Jeg har prøvet dette:

SQL = \"SELECT * FROM kalender WHERE Dato > #\" & Date() & \"#\"

Men det virker ikke.

Datofeltet i databsen er af typen \"Dato og Klokkeslet\".

Jeg har samlet et eksempel på mit problem i nedenstående fil, hvis nogen vil kigge på det.

http://home10.inet.tele.dk/Slash/dato.zip

Det er 2 filer: default.asp og db.mdb

Håber I kan hjælpe.
Avatar billede eagleeye Praktikant
02. november 2001 - 17:26 #1
SQL = \"SELECT * FROM kalender WHERE Format(dato,\'mm-dd-yyyy\') > #\" & Date() & \"#\"
Avatar billede vandhunden Nybegynder
02. november 2001 - 17:48 #2
Hmm, jeg mener at både Date() og Dato har dd-mm-yy
Avatar billede eagleeye Praktikant
02. november 2001 - 17:50 #3
Gennem SQL-kald bliver date konvertere til mm-dd-yyyy. Det er hvad jeg har været udsat for.
Avatar billede apocryphal Nybegynder
02. november 2001 - 20:41 #4
Det du leder efter, er datediff

SELECT * FROM kalender WHERE datediff(day, dato, getDate()) > 0





Data for datediff:
Returns the number of date and time boundaries crossed between two specified dates.
Syntax

DATEDIFF(datepart, startdate, enddate)

Arguments

datepart

Is the parameter that specifies on which part of the date to calculate the difference. The table lists dateparts and abbreviations recognized by Microsoft®
SQL Server™.

Datepart    Abbreviations
year    yy, yyyy
quarter    qq, q
month    mm, m
dayofyear    dy, y
day    dd, d
week    wk, ww
hour    hh
minute    mi, n
second    ss, s
millisecond    ms
startdate

Is the beginning date for the calculation. startdate is an expression that returns a datetime or smalldatetime value, or a character string in a date format.
Because smalldatetime is accurate only to the minute, when a smalldatetime value is used, seconds and milliseconds are always 0.
If you specify only the last two digits of the year, values that are less than or equal to the last two digits of the value of the two digit year cutoff configuration option are in the same century as the cutoff year. Values that are greater than the last two digits of the value of this option are in the century that precedes the cutoff year. For example, if two digit year cutoff is 2049 (default), 49 is interpreted as 2049 and 2050 is interpreted as 1950. To avoid ambiguity, use four-digit years.

For information about specifying time values, see Time Formats. For information about specifying dates, see datetime and smalldatetime.

enddate

Is the ending date for the calculation. enddate is an expression that returns a datetime or smalldatetime value, or a character string in a date format.

Return Types

integer

Remarks

startdate is subtracted from enddate. If startdate is later than enddate, a negative value is returned.
DATEDIFF produces an error if the result is out of range for integer values. For milliseconds, the maximum number that can be represented is 24 days, 20 hours, 31 minutes and 23.647 seconds. For seconds, the maximum number that can be represented is approximately 68 years.
The method of counting crossed boundaries such as minutes, seconds, and milliseconds makes the result given by DATEDIFF consistent across all data types. The result is a signed integer value equal to the number of datepart boundaries crossed between the first and second date. For example, the number of weeks between Sunday, January 4 and Sunday, January 11, is 1.

Examples

This example determines the difference in days between the current date and the publication date for titles in the pubs database.

USE pubs

GO

SELECT DATEDIFF(day, pubdate, getdate()) AS no_of_days

FROM titles

GO
Avatar billede vandhunden Nybegynder
03. november 2001 - 10:10 #5
apo..> Flot flamet!

Jeg fandt en løsning i et andet spm. Noget med at konvertere dato til et tal med clng(dato). Pisse smart.

Alligevel tak for hjælpen.

/Andreas
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester