Given a variant, does VBScript have an equivalent of C#'s DateTime.TryParse method?
相关问题
- convert string to DateTime in C# with EDT at the e
- Jackson to deserialize Joda LocalDate from ISO Dat
- SQL - Convert Time Series Events into On/Off Pairs
- How to programmatically convert Access 1997 .mdb t
- @DateTimeFormat in Spring produces off-by-one day
相关文章
- How to truncate seconds in TSQL?
- How to remove seconds from datetime?
- OLS with pandas: datetime index as predictor
- Calculate number of working days in a month [dupli
- How can I convert a OLE Automation Date value to a
- Can a VBScript function return a dictionary?
- Out of bounds nanosecond timestamp
- How to serialize Xml Date only from DateTime in C#
I believe the challenge is to make the solution independent of local regional settings which is a pre-req in many situations.
The only way I found is to use DateSerial() since ParseExact() does not exists in vbs.
I think below code does the trick. There should be a smoother way to add the time component but I didn't find it. Of course this exact code only covers one input format, but that's all I need for now.
Use IsDate(stringDate) in conjunction with CDate(stringDate).
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.