How to find a date and time stamp in a file using VBscript? - vbscript

I have an online temperature logger that publishes the date and time of last measurement in a file.
I need to find the date and time stamp in the html file using VBscript, and then check if it's older then 2 hours comparing to current time.
Example date format: 12.04.2013 16:45

You could extract the timestamp with a regular expression
\d{2}\.\d{2}\.\d{4} \d{2}:\d{2}
However, due to the characteristics of HTML this is prone to error (line-wrapping, inline tags, …), so a better approach would be to extract the date from the HTML using DOM methods (e.g. getElementsByTagName().
Once you have the date string, you can use the DateDiff function to calculate the difference to the current timestamp:
DateDiff("h", datestring, Now)

Related

Changing format of date without using to_char - Oracle

I have to get the max payment date on an invoice and I am having trouble with the date format. I do not need the max in this formula as I am using the format in a reporting tool that is pulling the max from what it finds for me.
Using "to_char({datefield},'mm/dd/yyyy')" works for displaying that date the way we would like BUT when you use summary function MAX it does not pull the correct date because it is looking at a string and not a date (it will think 12/3/21 is larger than 3/2/22).
Another thing I have tried is trunc - "trunc({datefield})" which gives us the correct max date but it changes the formatting. For example if the date prior to the formula being applied is "8/12/21 12:00:00:000" the trunc formula will display it as 12-08-21 which is horribly wrong.
Long story short is I need a way to change a date/time to date with the format of 'mmmm/dd/yyyy' WITHOUT converting it to a string with something like to_char. Thank you!!!!
A DATE is a binary data type consisting of 7 bytes representing: century, year-of-century, month, day, hour, minute and second. It ALWAYS has all of those components and it is NEVER stored with any (human-readable) format.
What you are seeing when a date is displayed is the client application you are using to access the database making a decision to be helpful to you, the user, and display the binary DATE provided by the database in a human-readable format.
If you want to change how the DATE is displayed then you either need to:
Change the settings on the client application that controls how it formats dates when it displays them to you; or
Change the data-type so that it is no longer a DATE (which does not have a format) to a data type where the values of the date can be formatted (such as a string). You can do this using TO_CHAR.
If you want to find the maximum then do it BEFORE applying the formatting:
SELECT TO_CHAR(MAX({datefield}),'mm/dd/yyyy')
FROM your_table;

Easiest way to access .NET TimezoneInfo from Asp classic page [duplicate]

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?

jqGrid search - Convert search input from date string to epoch integer before performing search

I have a column that displays date strings such as "04/28/2017 3:00 PM". The data for this column are actually integers (epoch) such as "1493411432". jqGrid allows me to define a formatter to generate the date strings from epoch values for display in the grid column. The problem is that if a user wants to specify in the search dialog something like "End Time greater than "04/28/2017 3:00 PM"", it won't work because "04/28/2017 3:00 PM" will be compared with the interval epoch values. Does jqGrid provide any hook such that I can convert the date string to its corresponding epoch value which can then be used by jqGrid to do the search? Any other suggestions will also be appreciated.
If I examine Date(1493411432) the Apr 28 2017 23:03:32 GMT+0200. If you want to allow the user to filter (to search) for such dates then you should solve one more problem: to filter for date ignoring the time (or at least seconds or other minor parts of the time).
Relatively simple and flexible solution of the problem exist in free jqGrid fork of jqGrid, which I develop. It provides custom filtering feature, which get you full control to define custom searching/filtering operation and to define how it should be implemented.
Try the demo, which I created for the answer. You can filter for 4/15/2015. I think that it's very close to what you need and you can easy modify the code corresponded your requirements.

Comparing dates in Xpath with different formats

I have a date in this format "21-Mar-2014"
I already tried to search for Xpath formulas but with no use
I am getting the first format 21-Mar-2014 using SeleniumIDE and want to check if this value is the date of today,
So how can xpath generate today's date and compare it for the date extracted using Selenium
You can parse the string into a date with an xpath function such as date:date(string) (described in this question).
Today's date already in xml date format is supplied by fn:current-date() (see here)
You can get the value, sore it in a variable, and then compare it. Eg:
storeText //xpath/goes/here myDate
storeEval (new Date(storedVars['myDate']) > new Date()) isAfterToday
Note, the storedVars array holds all the variables.
new Date should parse most formats, otherwise you can use any javascript in the storeEval stage to reformat it.

The format of the date is changed to make a reload in my jqGrid, my date format is changed

I have the date format in my jqGrid as: 08.13.2015 0:00
When running a procedural reload from ajax consulting my webService, my database returns the date in this format 2015-08-13T00: 00:00
I have never seen this format with the T.
ISO 8601 format of complete date, plus hours, minutes and seconds
The "T" indicates the beginning of the time sequence.

Resources