Hello - I have a text field that I need to use in a formula in script, but I don’t know how to do it. Can anyone help?
I need to say:
If doc.(mytextfield) >= (thesysdate) Then
go on with other code that is working fine, but how to state that line above? I know in formula language I can use @TextToTime - anything similar in scripting? Thanks in advance!
Subject: How to set text to date for comparison in scripting?
Hi
You can try CDat function or DateValue ( stringExpr )
CDat : Converts a numeric value or string value to a date/time value.
DateValue:Returns the date value represented by a string expression.
Please let me know if you have any question
Harshak
Subject: RE: How to set text to date for comparison in scripting?
Hi Harshak - From Notes Help and doing more searching on this site, I’ve come up with:
Dim dateV As String
dateV = doc.GetItemValue(“ExpDate”)(0)
If (Cdat(dateV)) >= dtToday Then
However, I’m getting a type mismatch on that last line. Any ideas?
Subject: RE: How to set text to date for comparison in scripting?
Subject: RE: How to set text to date for comparison in scripting?
better way is to convert that field value to notesdatetime class then you can compare easily
i think it will give you idea
Subject: RE: How to set text to date for comparison in scripting?
Don’t really care. It’s a BAD way to code, and you will have troubles with it.
Do it right the first time - it’s easier in the long run, and you won’t keep running into problems.
Subject: How to set text to date for comparison in scripting?
You should never use a Text String to store dates. Format differences between countries and user’s preferences make the processing of that data difficult.
Store the dates in Date fields. If you need to display the date as text, use a computed field that builds the text date from the real date.
Subject: RE: How to set text to date for comparison in scripting?
Thank you, Graham, but we are only using this internally, it won’t be going out to any other time zones or countries. I am importing the data from another source and when importing into my date field it turns the data into a number - therefore I have to manipulate. It was easier to get it to export as text and manipulate it that way.
Subject: RE: How to set text to date for comparison in scripting?
Just because nobody in another country or time zone is using it (now) doesn’t mean you can assume everybody’s workstation will format dates the same way. Date formatting is a user preference, and someone who, let’s say, comes from Europe, may well continue to use the European date ordering even though they are now living and working in USA.
Furthermore, dates stored as text can’t be searched using a range of dates in a full-text search, they don’t sort chronologically, and as Graham said, it’s just sloppy.
Subject: RE: Excuse me your grace…
Will,
The point is, fix the data while you can. We all get passed data from systems that format it various ways. If you choose to just accept the data as text it will come back and bite you later.
Spend the time to do it right. (Which we may all be agreeing upon).
I’m on contract to a large multi-region corporation. Yet the “U.S.” folks all the time work with things set to their regional preference and then we have to support the users in the rest of the world who do not conform to those defaults.
I’m so tired of having to explain to the U.S. folks you cannot store a number in a TEXT field because “1.43” is valid for you, but in Quebec it’s 1,43. Therefore a field holding “1.43” entered by someone in the U.S. then multipled by the “1,43” entered by someone in Canada is @Error.
The only reward is watching their heads explode at learning that a comma can be a decimal place holder.
Subject: RE: Excuse me your grace…
Subject: RE: Excuse me your grace…
But what good is preaching, “fix the data” when the person obviously didn’t have the knowledge required to do so?
That’s not obvious to me. She knows @TextToTime – it’s not that hard to write a formula agent to fix the field in all documents. And that’s the right way to do it – answering the question about how to do the comparison would be a disservice.
Subject: How to set text to date for comparison in scripting?
what about evaluate
dim vCompDates as variant
vCompDates = evalaute(|@If(@date(@texttotime(textfield)) = @today); “Equal”;“Not Equal”)|,doc)
If vCompDates(0) = “Equal” then
blah blah blah
end if