In a VBScript, I need to initialise a variable with a date. In my country we usually specify a date with this format: day month year
Here is what I'm trying to do in my VBScript:
Date = #07-06-1973#
MsgBox FormatDateTime(Date, vbLongDate)
but the date I get is July the 6th, where I was expecting June the 7th!
Now, as it seems the first number represents the month, here is what I tried to do:
Date = #13-06-1973#
MsgBox FormatDateTime(Date, vbLongDate)
but now, the first number represents the day! (I get the following date: June the 13th)
I haven't found a way to force the date format, so that there is no more ambiguity.
Strictly speaking, VBScript supports date literals in the US and ISO formats only:
' US format:
Date = #10/19/2009#
' ISO format:
Date = #2009-10-19#
However, the date separators can be different (slash, dash, space etc), and the VBScript engine also recognizes dates containing abbreviated month names (#Oct 19, 2009#) and non-ambiguous dates with swapped date parts (#2009 19 10#). The latter explains why #13-06-1973# in your second example is recognized as June, 13th: the number 13 falls outside the acceptable range of months (1-12) so it's interpreted as the day part.
If you want to specify dates in your regional format (that is, the format specified in your Regional and Language Options), you can use the CDate function to convert date strings, for example:
' Russian format
Date = CDate("19.10.2009")
But using US and ISO date literals are more reliable and preferred.
Related
I have period date compose by 6 numbers, the first four numbers it’s the year and the last two is the month, example: yyyymm. (202201 )
The problem with this field is that sometimes changes between int and string. How can I change everything to a date format? dd/MM/yyyy
How can I change everything to a date format? dd/MM/yyyy
I used <#setting date_format="mm/dd/yyyy"/> to set my date format. However, When I print the dates, it always print 00/xx/xxxx, 0th month.
mm means minutes, not months in year; use MM for that: MM/dd/yyyy. See: https://docs.oracle.com/javase/7/docs/api/java/text/SimpleDateFormat.html
I'm trying to change some old .asp files with vbs. Our database is going to be converted to store dates in UTC, but on webpages it should show dates and time in "Europe/Helsinki" timezone(
TimeZoneInfo.FindSystemTimeZoneById("FLE Standard Time")
in c#). How can I cast the UTC date I get from db query( the query is run in the .asp file as well and the result put into table) to correct date time using vbscript?
Just offset the UTC dates using DateAdd().
Const EETOffset = -2 'EET offset from UTC is -2 hours
Dim dbDateValue 'Assumed value from DB
Dim newDate
'... DB process to populate dbDateValue
newDate = DateAdd("h", EETOffset, dbDateValue)
Note: One problem with this approach is you will also have to compensate for EET and EEST (Eastern European Summer Time) manually based on the time of year. Which is also more difficult when you take into consideration some places don't use it and use EET all year round instead.
See EET – Eastern European Time (Standard Time).
Depending on the RDMS you are using you should even be able to manipulate the dates before they get to the page as part of the initial query.
Useful Links
Format current date and time
How to format a datetime with minimal separators and timezone in VBScript?
I ran an SQL Query for Oracle which consists of Invoice date and Check date. When these data are copied on to an Excel Spreadsheet as text, it's dispayed as ex: "13-10-31" (Oct 31, 2013). However, when converted to date format, it's displayed as "10/13/1931". I've tried different date types but it always recognizes as the first part of the text as the day, then month, then year. I need these values to be setup as a date format as I need to calculate Days Payable Outstanding and other related ratios.
Is there any way to convert these values so that Excel recognizes the day, month, and year correctly? Would there be a macro that could automate this process for existing data and data that will be added in the future?
Thank you in advance.
Firstly, I hope the data type of your date column is DATE.
Secondly, the date should always have year as YYYY and not just YY. The world has already learned from Y2K bug.
If above two points are met, then while displaying use to_char(date_column, 'mm/dd/yyyy'). Thus, with YYYY format, there won't be any confusion between year and other fields.
for example I have this date jan 5, 2010 14:00 wednesday gmt-8
how do I implement this so I can save it with timezone?,
I can save this using nsformatter with yyyy-MM-dd hh:mm
and saves as
2010-01-05 14:00
but how about w/ timezone?
(it should be saved in datetime format.. not text format)
You can use [format setDateFormat:#"yyyy-MM-dd hh:mm a"] for timezone it will give output like this "2010-01-05 02:00 PM"
or
[format setDateFormat:#"MMM dd, yyyy hh:mm a"]
Put the timezone in another column and you won't break the limited existing date functionality of SQLLITE. Its really easy to add columns to sqllite with an alter table statement. Android SQLite Database, WHY drop table and recreate on upgrade
SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values:
TEXT as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS").
REAL as Julian day numbers, the number of days since noon in Greenwich on November 24, 4714 B.C. according to the proleptic Gregorian calendar.
INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC.
Applications can chose to store dates and times in any of these formats and freely convert between formats using the built-in date and time functions.