I have an application form, where i placed text item where the user enter manually a year like for example: 2016.
I tried to enforce the user to enter correctly the year on its format, not for example charcters or numbers.
Any way to that?
Thanks everyone!
Can you update the form yearly and if so to make it work universally you could just convert to an int and check if intYear = currYear. I mean there are a lot of other fixes including if Year>= 2016- then allow which could still get you things like 9999 but then you could do a opposite. Although ultimately the most efficient would be getting the computers year which may propose challenges but would work for more year and only have problem with people who have incorrect year.
The year should be entered as a number. You can verify that it is an integer, that it is <= current year, and >= 1993 (for example), like this:
... yr = round(yr) and yr between 1993 and extract (year from sysdate)
Honestly, I am not familiar with Oracle forms; this may be a check, for example, in an "if ... then ... else" structure in a stored procedure, and raise an error if the condition is not met. yr is the name of the input variable. If the user enters '2015' (with the single quotes) instead of 2015 (as a number) Oracle will likely convert it to a number, silently and without warning, and it will pass the test - but then you can safely assume the user really meant to enter 2015; no harm will result.
Related
I am brand new to Dialogflow CX and am having trouble figuring out how to use a date in a condition. I want to require that a birthdate be entered and be greater than 2000-01-01. I have tried
$intent.params.dob.resolved > 2005-01-01
with and without quotes, but it does not work (always false). I discovered that $intent.params.dob.original > "1/1/01" is resolved as True for all dates, so that is of no help.
Is there a way that works?
To achieve your described use case, you can utilize the condition route or conditional response to return a response according to the condition. Here is a condition you may use:
$intent.params.birthdate.resolved.year > 2000 OR
($intent.params.birthdate.resolved.year = 2000 AND
$intent.params.birthdate.resolved.month > 1) OR
($intent.params.birthdate.resolved.year = 2000 AND
$intent.params.birthdate.resolved.month = 1 AND
$intent.params.birthdate.resolved.day > 1)
Here are examples for your reference:
A. Using the condition in the Conditional Response
B. Using the condition as the Condition Route:
Please note that the birthdate parameter isn’t a string parameter. It is composed of year, month, and day sub-parameters so it is appropriate to utilize them for your use case. Also, note that dates are in ISO-8601 format. For more information, you can refer to the System Entities documentation.
Here are the following results using the condition defined in the conditional response:
When the user enters the same year but not January 1st
When the user enters an invalid date
When the user enters a previous date from 2000-01-01
When the user enters a valid date and latest from 2000-01-01
I guess $intent.params.dob.resolved returns a string, so you need to build a date object firstly, and then compare it with your date.
I encountered a similar problem a few weeks ago. Thing is, Dialogflow actually defaults to string parameters: this means that every value entered as a parameter will (by default) be a string, surrounded by "quotes".
To operate comparisons between dates you'd want to compare integers/numbers, and I think the best way to do so is to take advantage of date system entities.
For example, the system entity
#sys.date
allows you to match a date inserted by the user. Then the best part is, in your condition, you can even manage the date by referencing sub-parts. Here is an example:
if $intent.params.dob.year <= 2005 AND $intent.params.dob.month <= 04:
I'm sorry, you're too young to use this service!
endif
Also, on a side note, "intent parameters" actually become "session parameters" as soon as Dialogflow makes a step from the state in which the parameter was set to another page.
This means that if you set the parameter dob when the user says "I was born on the thirteen of July, 2004" and then you go on to a new page, that parameter will only be accessible as $session.params.dob (and session parameters don't have a "resolved value", they are resolved by default).
So, to recap. Make sure you're using the system date entity. Make conditions for all the parts of the date you need to verify (year, month, day) and try to use your parameter as a session parameter.
I hope at least some of what I wrote can help you, happy bot-building!
I have a data set in which month and year are in one variable and come in the form 200801 which equates to 2008, January. How can I create a SAS date from this integer?
I would like something in the form of Jan 2008 - anything so that SAS recognizes it as a date, as I then need to subtract this value from service date to find out how much time has elapsed since enrollment into the dataset until date of service.
Please also keep in mind that this is a variable, and I have thousands of observations. So I also need the data step/ function to do this for the entire variable.
Any help is appreciated!
You need to put it to a character variable, then input back to numeric. You can do that pretty easily.
date_var = input(put(date_var_orig,6.)||'01',yymmdd8.);
You can also do it this way:
date_var = mdy(mod(date_var_orig,100),1,floor(date_var_orig/100));
Both assume you want the day to equal 1; make a choice there if you want something else (like end of month or middle of month).
I'm using informix DB 11.70, and this issue is ticking me off pretty badly.
When I insert a client into my DB, no matter what date I input, when I fetch back the date it brings some random date in 1894.
What issue could it be? It throws no errors when I send entries, no 'Invalid month in date' nonsense.
Pls help.
The "epoch date" for Informix is 01-01-1900. In other words, date ZERO = "12-31-1899", date 1 = "01-01-1900", date 2 = "01-02-1900", today ("09-24-2013") is stored numerically as 41540.
I think either your client application is being too clever by half, or you aren't putting quotes around your dates, and either way the server is treating your dates as numeric calculations.
In other words, you enter something like 05-11-2010, and your client sends that to the database as 5 minus 11 minus 2010, or -2016. Day number -2016 is "06/24/1894".
I bet if you enter your dates with a slash rather than a dash (i.e. "09/24/2013"), you'll always get 9 divided by 24 divided by 2013 = close to zero => "12/31/1899".
You haven't said if you're using plain old SQL via DB-Access, or ODBC, or something else. But I'll guarantee your dates are not being enclosed in quotes, and are therefore getting treated as arithmetic expressions.
Upon logging into their accounts, each user has their login date and time stored to the database. What I was looking to do however is figure out the amount of days (or preferably convert into months if greater than a month) so that if a user views their profile they can see how active the band are. Also, this could benefit me in terms of keeping active profiles top of the agenda for content on the site so that it doesn't become stale from inactive users content filling up main page content.
I'm using ColdFusion so i'd be looking for a way to find for example how many days ago #lastLogin# was from #now()#. So say if the date of the last login was 23/04/2013 and todays date is 29/04/2013 it would read "Last Active, 1 day ago." However if the last login was 23/03/2013, it would read "Last Active, 1 month ago".
Anybody know how to do this? Thanks.
P.S I currently have no code from testing this as I have no idea where to start in terms of achieving this.
Use DateDiff
<cfset days = dateDiff("d", LoginDateVariable, now()) />
It's as simple as that.
P.S I currently have no code from testing this as I have no idea where
to start in terms of achieving this.
This doesn't answer your direct question but to help you know where to get started, I would strongly suggest reviewing the built in ColdFusion functions and tags that are available to you.
Tags
Tags by function
Functions
Functions by category
Also, Google searches usually land you at the docs, just add "coldfusion" to your search string. Searching google for coldfusion date functions yields very helpful answers, the first of which are a list of all ColdFusion date functions.
Dale's answer is spot on. But I would also suggest returning it as a variable with your query. Let the SQL server do the work. It's very efficient for those types of calculations. Not that CF can't do them well, too. But it's probably more appropriate for SQL to do that lifting. Especially if you're already returning the lastLogin date.
It would be similar to the CF solution:
SELECT ...., lastLogin, DATEDIFF(d, lastLogin, GETDATE()) AS LastLoginDays
FROM ....
WHERE ....
That would give you the number of days. You'd have to decide how you wanted to define a month if you wanted to break it out by month/day. That would get a bit more complex. You could write a SQL function that could be run on both dates and give you an accurate count of days/months/years since last login.
One other thing to keep in mind: Where are the dates being generated? When you insert loginDate into the database, are you doing a now() in CF before you insert it or are you doing a getDate() in SQL when you insert it? Again, I would let the database do your date logic, but you'd want to compare the two dates from the same source. For instance, if your loginDate was a database getDate() then you may not want to compare that to a CF now(). One goes by the datetime of the SQL server and the other goes by the datetime of the CF server. They could be different.
I have a weird issue with MS ACCESS 2010.
I have a table RawData with column TaskDate (format is Memo). When I use the below query I am getting the desired data,
`select * from RawData where TaskDate between '01/01/2012' and '12/31/2012'`
But when I use the below query I am not getting any data:
select * from RawData where TaskDate between '01/01/2012' and '01/01/2013'
I don't understand the problem as the data comparison was not happening with this 'Year' value. Please help on this
Oh dude. You realize how bad that is? "No idea how to use a database" style, sadly. Time for reading documentation on data types.
Ok, here we go:
TaskDate (format is Memo)
Yes, and however did that should be publicly flogged. First, this is a TEXT field, second it is for LONG texts which dates never are. Fail on two levels.
If the format is Memo it is text, so "between" compares texts.
'01/01/2012' and '12/31/2012'`
that is left to right.
i.e. first letter 0 or 1, second letter 1 or 2, 4th letter between 0 and 3, 5th letter between 1 and 1. Goes on...
'01/01/2012' and '01/01/2013'
that would mean basically everything of 01/01 on 2012 and 2013 ONLY. Assuming this is a holiday, without tasks - well, no data. Why? because any other date fails. The first characters have to match '01/01/201'.
If you would like do do that properly, you can:
Change the formatting of dates to make sense as text. THat is ISO norm: 2012-01-01 to 2012-12-31. That means they order correct as they go left to right.
Better: Dump the stupid idea to use Memo for dates
Read
http://www.dummies.com/how-to/content/tips-for-choosing-field-types-in-access-2010.html
then use Date/Time as field type, and magically Access will not try to compare texts (which is has no clue what they mean internally, so it can not apply the semantics of dates to them) and compare real dates.
Right now you made sure there is no "date" comparison. It is pure stupid little string, left to right, character by character, no additional logic.