![]() ![]() This of course doesn’t happen if the day is greater than 12 (because the script engine surely knows that there are only 12 months and it will adjust for our laziness for dates like: “” or “”).Īnd no exceptions were thrown. Actually…it didn’t switch them around but we hoped it would! Like, why didn’t Microsoft realize that what we meant was the 3rd of May!? – just kidding. The script engine switched the month and day around when the locale was reset to one which isn’t consistent with the original input. Let’s start with a value that we know is a date: “Now()”Įnter fullscreen mode Exit fullscreen mode The script engine will correctly interpret the value as a “Date” data-type even in various locales. Basically I will assigned a VBScript variable a value of “Now()” and then pass that information through other date-related functions. The table below demonstrates how the date functions usually operate just fine. I’m sure by now you understand the depth of the problem and you’re starting to wonder if you can afford the bartender’s tab. Perhaps the application will connect to a SQL database hosted in España.Īnd perhaps the users of the application will be scattered around the globe and speak all 6800 known languages and they don’t want to have to think about whether “DD” comes before or after the “MM” and whether “YYYY” should be abbreviated to just “YY” and separated with a “/. The HTML pages will be written entirely in Turkish – but the client wants to display currencies and dates in “British Pounds” and “en-gb” instead of Euro or the Turkish Lira. Perhaps your ASP application will be hosted on a web server in France so functions like CBool() produce “VRAI/FAUX” instead of “TRUE/FALSE” – I didn’t know that until my app broke on a server in France! VBScript is decidedly a “US English” language. The problems are amplified in multi-lingual situations. The solution is CDbl(), more on that later… But if your system’s Regional Settings change or if you utilize VBScript’s “SetLocale()” function or alter the “.CodePage” or “.LCID” properties of ASP’s “Response” object, then you should expect problems and the above functions aren’t reliable. ![]() If your database, your application and your web server all reside on a single computer (or multiple computers with identical Regional Settings). As far as I can tell, these functions work well if your application resides and operates in a very cohesive and structured environment. That’s the tragic flaw and there’s no method to enforce strong data-types. There are implicit data-type conversions happening all the time – regardless of how careful a programmer tries to be.Īnd the built-in functions above only work reliably when the arguments are a predictable data-type they’ll break or produce unexpected results if they must perform implicit data-type conversion. I mean that VBScript is not a strongly-typed language - it’s loose and happily changes our sloppy variables from strings to dates to numbers and back. Frankly, I’ve found only DateAdd() and DateDiff() to be of any real help and the others can be avoided altogether.Ī great function! But it has to be treated carefully. I recommend you ignore all of them except “Now()”!ĭateAdd(), DateDiff(), DatePart(), DateSerial(), DateValue(), TimeSerial(), TimeValue() These produce – supposedly – a value of type “Date” based on the system’s current date/time. Intended to convert a variable of type “(something)” to a variable of type “Date” but it can lie and is sometimes lazy. It’s inherently flawed and its output can’t be trusted. This is supposed to help you determine if a variable is of type “Date”. VBScript includes the following functions which are intended to manage date/time data: If you are reading this article, it’s because you’ve realized those built-in functions appear to be fundamentally flawed. VBScript has built-in functions to help manage dates, numbers, currencies, and other data types. Instead, use a data-type that VBScript will (almost) never screw up: the “DOUBLE”. I really mean this: avoid using dates whenever possible! ![]() Especially in multi-lingual environments. Working with dates in ASP/VBScript makes me want to bludgeon my skull with a blunt object. Otherwise, stay for some tips when working with Classic ASP. If you are lucky enough to never have to work on legacy code, leave this page.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |