24. september 2001 - 15:24Der er
6 kommentarer og 1 løsning
str til date
Jeg har en mysql database hvor jeg har noget tekst. Det tekst er en DATE... Men i databasen er det angivet som text char(255). Hvordan kan jeg lave det om til en date string?
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.
...og:
FormatDateTime Function Returns an expression formatted as a date or time.
FormatDateTime(Date[, NamedFormat])
Arguments Date
Required. Date expression to be formatted.
NamedFormat
Optional. Numeric value that indicates the date/time format used. If omitted, vbGeneralDate is used.
Settings The NamedFormat argument has the following settings:
Constant Value Description vbGeneralDate 0 Display a date and/or time. If there is a date part, display it as a short date. If there is a time part, display it as a long time. If present, both parts are displayed. vbLongDate 1 Display a date using the long date format specified in your computer\'s regional settings. vbShortDate 2 Display a date using the short date format specified in your computer\'s regional settings. vbLongTime 3 Display a time using the time format specified in your computer\'s regional settings. vbShortTime 4 Display a time using the 24-hour format (hh:mm).
Remarks The following example uses the FormatDateTime function to format the expression as a long date and assign it to MyDateTime:
Function GetCurrentDate \' FormatDateTime formats Date in long date. GetCurrentDate = FormatDateTime(Date, 1) End Function
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.