I have an excel form which accepts time in 24 hours as hh24:mm:ss.
I gotta check if the entered time is valid or not.
My problem is when I enter valid times like 12:23:23, it catches the value as it is. But when I enter invalid times like 25:34:12, it converts it into valid time as 01:34:12. So I am not able to validate the data.
Why is it so? And how can I stop this from happening?
I am taking the value in variable as:
timeVal = Application.WorksheetFunction.Text(ActiveSheet.Range("F" & i), "hh:mm:ss")
You can use text-to-columns, based on : as a delimiter. Then you can use an IF statement to determine if each section (or just the first) is invalid (greater than 23).
=IF(B2>23,"Invalid","Valid")
You can also use a formula on this.
I would also recommend change the formatting of the time field on your form, to protect the integrity of future data. To do that, go to format > custom > hh:mm:ss AM/PM.
Related
We are looking to compare the calendar start date with the current date in flow. Currently we are pulling the start date through a filter query like this:
formatDateTime('EventDate','M-d-yyy hh:mm')
and comparing to this:
formatDateTime(addDays(utcNow(),3),'M-d-yyyy hh:mm')
I am getting this error currently: "Unable to process template language expressions in action 'Get_items' inputs at line '1' and column '17987': 'In function 'formatDateTime', the value provided for date time string 'EventDate' was not valid. The datetime string must match ISO 8601 format."
Any help on this would be greatly appreciated!
You could Initialize a variable like the following below and then do a IF condition.
#{add(div(sub(ticks(utcNow()),ticks('1900-01-01')),864000000000),2)}
I test with the same formula to convert event start date and it works fine in my end. The if condition returns correct result on different conditions.
Here is the logic of my demo flow, please have a check:
I use get item to get the start date of a certain event in the calendar list and convert the start time dynamic content to the format I need. Almost same with yours.
According to the error message, it seems the format of the event date column is not in the supported format. Would you like to provide the settings of your event date column? I test with the default start time column and a custom date & time column of default settings. Both of them works fine with the flow above.
Update:
The two formulas used are displayed below:
formatDateTime(outputs('Get_item')?['body/Event_x0020_Date'],'M-d-yyy hh:mm')
formatDateTime(addDays(utcNow(),3),'M-d-yyyy hh:mm')
I just directly use the outputs of the data compose action in the if condition
What worked for me was to build a sequence of numbers with the dates being ordered by day, month and year this way, when converting to integer, it's easy to compare
int(formatDateTime(utcNow()),'yyyyMMdd'))
if you need add day for exemple, you can use
int(formatDateTime(addDays(utcNow(),variables('extraDays')),'yyyyMMdd'))
and the other date like this
int(formatDateTime(variables('FinalDate'),'yyyyMMdd'))
Based on your example, you can put hours and minutes without any problems, just remove the special characters and spaces
but by the definition of the error you are having, I believe it is because of the way you are writing the variable
=text(5/7/19,[Windows date format]) depends on the computer you are opening the Excel file from. For instance: =text(5/7/19, "mm/dd/yy") works on the company computer because that's how the windows formatted the date, but in my computer, it has to be =text(5/7/19, "dd/mm/yy") else it will return a different value and using other functions such as =datevalue(text(5/7/19, "mm/dd/yy") will return a #VALUE! error on my home computer. This is not good because it is very variable when the file is being moved around computers. How to standardize this?
So what about:
=TEXT(43592,"mm")&"/"&TEXT(43592,"dd")&"/"&TEXT(43592,"yy")
Or reference a cell where you have put your date.
Unfortunately I don't think it is possible - see the this link
Quote:
Problem: The value in the date_text argument is not in sync with the system’s date and time settings*
If your system date and time settings follow the mm/dd/yyyy format,
then a formula such as =DATEVALUE(“22/6/2000”) will result in a #VALUE! error. But the same formula will display the correct value when the system's date and time is set to dd/mm/yyyy format.
Solution: Make sure that your system’s date and time settings (both Short time and Long time) matches the date format in the
date_text argument.
I think the only solution is to make sure that your date is in the valid (i.e. recognised by the system) date format before any other function (like DATEVALUE) is applied.
It will be easy to achieve if your function is simply =text(5/7/19,[Windows date format]). You can reference your cell field (e.g. =[#Date]) and format a given cell using an "universal" date format (the ones that start with * sign).
However, if you are combining =text(5/7/19,[Windows date format]) with some other formula (e.g. when you want to display a full sentence like A very important event happened on 5/7/19) then, unfortunately, cell format won't save you here and we're out of solutions. In such case the end user would need to manually modify the date cell in order to make it recognisable.
I have a userform and I take start and end dates from user as in dd.mm.yyyy format. To make it easier to compare dates, I want to turn it to a double or long type of value. I have tried as in below but it gives me an error of type mismatch.
endDate is already defined as Double and as you can see, Me.g_end.Value is string in proper format. Why do I get this error, and how can I handle it?
Also I need to add, DateValue(Me.g_end.Value) works fine with my friend to get value of date who uses Excel 2013. I use Excel 2016.
You need to enter dates in a valid format in order for Excel to recognize them as dates.
As far as I know, nowhere uses dots (periods) in dates. (As I recall, nowadays only one country in the world even recognizes dots as am official date separator.)
Click your Start menu and type Region to find and open Windows Region and Language Settings.
Note the format that your system is expecting for Short Date, including the symbol between each date part, and try entering your dates in Excel like that.
Since i spent some time trying to find the answer to this question I decided to pass the knowledge along to save other people some time.
If the current time is later than the set time, then TRUE
I use this to set up an alert if orders aren't finished after 3 o'clock:
=VALUE(TIME(15;0;0))<VALUE(NOW())-TRUNC(VALUE(NOW()))
What it does is check the numerical value for (in this case) 3 oclock in the afternoon and the numerical value of the current time and checks if it is later or not.
I hope it helps someone.
This will work if your set time has a date attached to it as well. If not, you will need to modify the NOW() equation to just look at the time stamp.
Replace the value of 'X' in the above equation with the cell reference of your "Set" time.
=IF(NOW()> X, "TRUE", "FALSE")
You can change the T/F values above inside the quotations to show whatever you like (like change false to blank maybe?).
If T/F are the only outputs you will need, this can be simplified to
=NOW()>X
Excel will evaluate the expression and return True or False.
I have a spreadsheet I created mid-August which has a table with one column for every day since then. The column header is the day's date. The date is displayed how I want it to be displayed: "dd/mm/yyyy"
However, I have macro which needs to read these dates in order to perform its work. Because I am using a table, the dates seem to be held as text rather than as 5-digit numbers (when I set the header cells' format to "General", it remains with the "dd/mm/yyyy" format rather than changing to a 5-digit number. This wasn't a problem until the 1st of September, after which CDate (in the macro) began reading these dates as "mm/dd/yyyy"
Is there any way to make CDate recognise the Australian date format rather than the American? Or failing that, make the table headers stay as dates rather than as text? I'd rather avoid having to convert the Table back to a range, as the macro is designed to use table attributes, ListColumns etc.
UPDATE:
I've narrowed down the problem. It isn't the date, but the ListColumn.Name property. For some reason it is re-converting my date. I'm using Format() to set the date format, like so:
CreateHistoryColumn.Name = Format(headerDate, "dd/mm/yyyy")
MsgBox Day(headerDate) & "/" & Month(headerDate) & "/" & Year(headerDate)
MsgBox Format(headerDate, "dd/mm/yyyy")
MsgBox CreateHistoryColumn.Name
Where CreateHistoryCol is an object of class ListColumn. The 3 MsgBox calls display the following:
6/9/2012
06/09/2012
9/06/2012
So the Format() call formats the date correctly, but the call to ListColumn.Name serves to alter the format to "mm/dd/yyyy".
From help file:
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.
I hate relying on the locale because most of the time it seems to do the opposite of what I intended, plus it makes code less portable.
I usually deal with dates as explicitly as possible:
Split your string into the various parts (year, month, day, as well as hour, minute, second if relevant)
Stick the various parts in the DateSerial function. This returns a Date type. (To that you can add the output of TimeSerial, if applicable.)
If necessary for display purposes, format this Date as appropriate using the Format function, which returns a string.
Here's a worked example.
As I showed in the update, the ListColumn.Name method was responsible for the unwanted conversion. I still don't know why, but there is any easy fix:
CreateHistoryColumn.Name = CLng(headerDate)
This forces the header to be treated as a number, and therefore it can be recognised as its proper date. I can't explain it any further than that.