12. januar 2003 - 16:06Der er
4 kommentarer og 1 løsning
Datoproblem *ARRRHGG*
Hej!
Jeg har et script til et booking system som virker sådan nogen lunde. Hvis jeg angiver aktuel dato via 'Date' virker det, men hvis jeg nu vil have det via en querystring variabel virker det ikke.
<% if request.querystring("date") <> "" then MyActDate = request.querystring("date") else MyActDate = Date-1 end if %>
Problemet opstår i linje 45 som er sådan her: MyDate = MyActDate + t
Problemet opstår fordi systemet ikke har nogen chance for at vide at MyActDate er en dato, den opfattes som en streng. Prøv at kigge på funktionen CDate.
Fra MSDN: Visual Basic Scripting Edition
CDate Function Returns an expression that has been converted to a Variant of subtype Date.
CDate(date) The date argument is any valid date expression.
Remarks Use the IsDate function to determine if date can be converted to a date or time. CDate recognizes date literals and time literals as well as some numbers that fall within the range of acceptable dates. When converting a number to a date, the whole number portion is converted to a date. Any fractional part of the number is converted to a time of day, starting at midnight.
CDate recognizes date formats according to the locale setting of your system. The correct order of day, month, and year may not be determined if it is provided in a format other than one of the recognized date settings. In addition, a long date format is not recognized if it also contains the day-of-the-week string.
The following example uses the CDate function to convert a string to a date. In general, hard coding dates and times as strings (as shown in this example) is not recommended. Use date and time literals (such as #10/19/1962#, #4:45:23 PM#) instead.
MyDate = "October 19, 1962" ' Define date. MyShortDate = CDate(MyDate) ' Convert to Date data type. MyTime = "4:35:47 PM" ' Define time. MyShortTime = CDate(MyTime) ' Convert to Date data type.
MyWeekDay = Weekday(Date) Select Case MyWeekDay Case 1 ' søndag Days = 1 Case 2 ' mandag Days = 7 Case 3 ' tirsdag Days = 6 Case 4 ' onsdag Days = 5 Case 5 ' torsdag Days = 4 Case 6 ' fredag Days = 3 Case 7 ' lørdag Days = 2 End Select
response.write "Der er " & Days & " dage til mandag"
Synes godt om
Ny brugerNybegynder
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.