Focal Point
[Solved] Is there a way to find out the format of user entered date?

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/1877034126

June 19, 2012, 01:04 PM
sumant
[Solved] Is there a way to find out the format of user entered date?
Hello All,

I have a question regarding finding out the format of the user entered date.
The user has to provide the Begin Date and the End Date for the report. The users dont want to be restricted to enter the dates in a particular format.
Is there a way using which we can find out the format of the dates the user enters. As these dates are being used as filters, finding out the format is critical.

Thanks for your time.

This message has been edited. Last edited by: Kathleen Butler,


WebFOCUS 7.7.02Windows
Output Formats: Excel, HTML, PDF
June 19, 2012, 01:37 PM
ABT
i don't know of any functionality that enables this short of EDITing out portions of the date and testing for a range of acceptable values (i.e. month token is between 1-12, Day token is not > 31). This has obvious drawbacks for dates where the day is <= 12.

The obvious solution is to use a calendar control and an HTML launch page to enforce the value selected. The calendar control brings its own bag of hurt with it, though.

- ABT


------------------------------------
WF Environment:
------------------------------------
Server/Client, ReportCaster, Dev Studio: 7.6.11
Resource Analyzer, Resource Governor, Library, Maintain, InfoAssist
OS: Windows Server 2003
Application/Web Server: Tomcat 5.5.25
Java: JDK 1.6.0_03
Authentication: LDAP, MRREALM Driver
Output: PDF, EXL2K, HTM

------------------------------------
Databases:
------------------------------------
Oracle 10g
DB2 (AS/400)
MSSQL Server 2005
Access/FoxPro
June 19, 2012, 01:38 PM
Doug
Yes there is. You can do an EDIT on the incoming value and check for "pieces" of it for normal expectations.
quote:
The obvious solution is to use a calendar control and an HTML launch page to enforce the value selected.





   In FOCUS Since 1983 ~ from FOCUS to WebFOCUS.
   Current: WebFOCUS Administrator at FIS Worldpay | 8204, 8206
June 19, 2012, 01:42 PM
sumant
Hello ABT,

I know of the EDIT function, but as I dont know the exact format being entered, I would have to come up with all the possible combinations and keep on checking with them till the exact one is met.
As you said, the calendar control might be the only option.


WebFOCUS 7.7.02Windows
Output Formats: Excel, HTML, PDF
June 19, 2012, 01:47 PM
Danny-SRL
Hello sumant,

What can you expect?
With slashes? Another delimiter? None?
4-digit year? 2-digit year?
European? American?
All?

I would check for one format and refuse the others!


Daniel
In Focus since 1982
wf 8.202M/Win10/IIS/SSA - WrapApp Front End for WF

June 19, 2012, 01:49 PM
Doug
I've done it. All you need to do is to account for ALL The Possibilities that the user can enter. Consider the following code:
-SET &DateIn = &DATEMDYY ;
-SET &DateIn = &MDYY ;
-TYPE *** Incoming date: &DateIn, check to see if it has slashes...
-SET &Slash = IF &DateIn CONTAINS '/' THEN 'Slashes' ELSE 'NoSlashes' ;
-TYPE *** -GOTO &Slash
-GOTO &Slash.EVAL
-Slashes
-TYPE Do something about the date with slashes
-GOTO TheEnd
-NoSlashes
-TYPE Do something about the date without slashes
-GOTO TheEnd
-TheEnd
-TYPE *** Ta Da
-EXIT
... You can use the EDIT and associated DM commands to limit it to accept only those dates which YOU want to accept and consider the rest as an erroneous input and act (branch) accordingly...
June 19, 2012, 01:51 PM
Doug
quote:
I would check for one format and refuse the others!
... or a limited set of acceptable formats...
June 19, 2012, 01:52 PM
sumant
Hello Daniel,

Currently there are no set rules for the date formats to be entered. I will have a talk with my users and ask them to give me their most commonly used formats for dates. Based on them, I will use the EDIT function and extract the dates.


WebFOCUS 7.7.02Windows
Output Formats: Excel, HTML, PDF
June 19, 2012, 01:53 PM
sumant
Hello Doug,

Thanks a lot for the sample code. I plan to ask my users for a limited set of acceptable formats and based on them extract the dates and use them in the filters.


WebFOCUS 7.7.02Windows
Output Formats: Excel, HTML, PDF
June 19, 2012, 02:03 PM
Doug
You're welcome.

About this:
quote:
Currently there are no set rules for the date formats to be entered.
... Someone needs to set some standards and we, as developers, need to accound for ANYTHING that we let in to our applications... Music
June 19, 2012, 02:43 PM
rfbowley
After many clients and and struggling with this for a few years, I try to talk each client into using the calendar control, with the edit box disabled. It is THE ONLY way to make absolutely sure the user does not type in an erroneous date.

This is the code I use for two calendar controls, defaulting to a 1 week date range, and producing a YYMD formated value to send to the report:

 
	var DateTo = new Date();
	var	DateToYear = DateTo.getYear();

	var monarr = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

	// check for leap year
	if (((DateToYear % 4 == 0) && (DateToYear % 100 != 0)) || (DateToYear % 400 == 0)) monarr[1] = "29";

	var DateToDay = DateTo.getDate() - 1;

	if (DateToDay >= 1){
		DateToMonth = DateTo.getMonth() + 1;
		}
	else {
		LastMonth = DateTo.getMonth() - 1;
		DateToDay = DateToDay + monarr[LastMonth];
		DateToMonth = DateToMonth - 1;
		DateToYear = DateTo.getYear;
		if (DateToMonth == 0){
			DateToMonth = 12;
			DateToYear = DateToYear - 1;
			}		
		}
	if (DateToMonth < 10){
		DateToMonth = "0" + DateToMonth;
	}
	if (DateToDay < 10){
		DateToDay = "0" + DateToDay;
	}




//  starting date calculations below here

	var DateFromDay = DateTo.getDate() - 8;
	if (DateFromDay >= 1){
		DateFromMonth = DateTo.getMonth() + 1;
		DateFromYear = DateToYear;
		}
	else {
		LastMonth = DateTo.getMonth() - 1;
		DateFromDay = DateFromDay + monarr[LastMonth];
		DateFromMonth = DateToMonth - 1;
		DateFromYear = DateToYear;
		if (DateFromMonth == 0){
			DateFromMonth = 12;
			DateFromYear = DateToYear - 1;
			}		
		}
	if (DateFromMonth < 10){
		DateFromMonth = "0" + DateFromMonth;
	}
	if (DateFromDay < 10){
		DateFromDay = "0" + DateFromDay;
	}

//alert (DateFromYear);
	StartDate = DateFromYear + "/" + DateFromMonth + "/" + DateFromDay;
	EndDate = DateToYear + "/" + DateToMonth + "/" + DateToDay;


    a=document.getElementById("calendar1");
	a.value =StartDate;
	a.disabled=true;

    b=document.getElementById("calendar2");
	b.value =EndDate;
	b.disabled=true;

    c=document.getElementById("calendar3");
	c.value =StartDate;
	c.disabled=true;

    d=document.getElementById("calendar4");
	d.value =EndDate;
	d.disabled=true;

 


I mean really, even if the end user follows the 'rules' and uses leading zeros and slashes, what date do they really mean by '03/05/07'. Is that:



So just testing for format is only half the job.


Robert F. Bowley Jr.
Owner
TaRa Solutions, LLC

In WebFOCUS since 2001
June 19, 2012, 02:57 PM
sumant
Hello Robert,

Thanks a lot for the detailed reply and posting your code.
Will try it out.
I still will talk to my users for a list of acceptable formats to avaoid any furhter confusion.


WebFOCUS 7.7.02Windows
Output Formats: Excel, HTML, PDF
June 19, 2012, 03:31 PM
Prarie
Oh Calandar controls is the only way to go. Think about any Web sites you go to that involves dates...they always have a calendar there. Can you imagine an airline trying to accommodate every way a person would put in a date?
June 19, 2012, 04:37 PM
susannah
if you have a text box, then in the html, set the maximum length to, say, 8
and populate the default value in the text box
value=yyyymmdd
and that exact character string, yyyymmdd, will appear in the box when the user opens the launch page. the user ought to be able to figure it out.
or..
use 3 text boxes: year, month, day
they can't possibly get that wrong.
(oh ok, they can!)

btw... can one of you 77'ers tell me if the calendar controls have been improved? in 76, the calendar only popped up within the calling frame, and that never works for me, so i either use external .js for my calendar (tiger comes to mind), or i use dropdown boxes.
but if 77 has fixed that so that the calendar will pop up wherever you tell it to, i'ld love to know....

This message has been edited. Last edited by: susannah,




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
June 19, 2012, 04:51 PM
ABT
quote:
Originally posted by susannah:
if you have a text box, then in the html, set the maximum length to, say, 8
and populate the default value in the text box
value=yyyymmdd
and that exact character string, yyyymmdd, will appear in the box when the user opens the launch page. the user ought to be able to figure it out.
or..
use 3 text boxes: year, month, day
they can't possibly get that wrong.
(oh ok, they can!)


+1 - Unless you are a consultant who has to do the bidding of the person paying your fee or maintain an externally focused site that you don't wish to turn people (and their money) away, I'd suggest showing the user's the format expected and let them decipher the needs.

I can yell at my TV all day long for not changing channels when I press the volume buttons and as developers, we should not be expected to 'intercept' their intentions. Only judge their actions.

- ABT


------------------------------------
WF Environment:
------------------------------------
Server/Client, ReportCaster, Dev Studio: 7.6.11
Resource Analyzer, Resource Governor, Library, Maintain, InfoAssist
OS: Windows Server 2003
Application/Web Server: Tomcat 5.5.25
Java: JDK 1.6.0_03
Authentication: LDAP, MRREALM Driver
Output: PDF, EXL2K, HTM

------------------------------------
Databases:
------------------------------------
Oracle 10g
DB2 (AS/400)
MSSQL Server 2005
Access/FoxPro
June 19, 2012, 05:51 PM
Waz
As it has been repeatedly stated, the calendar control is the only way to go, to be sure.

Otherwise, an entry field limited to 8/10 chars with a stated format that is accepted.

e.g.
Format DD/MM/YYYY

If they enter the date 01/12/2012, and expect it to be the 12th of the Jan, then its there own fault for not reading the screen.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

June 20, 2012, 08:56 AM
sumant
Thanks everyone for your replies.
I spoke to my users and we have agreed to use calendar controls.


WebFOCUS 7.7.02Windows
Output Formats: Excel, HTML, PDF
June 20, 2012, 03:28 PM
ABT
quote:
Originally posted by sumant:
... and we have agreed to use calendar controls.


And so the fun begins... Wink
- ABT


------------------------------------
WF Environment:
------------------------------------
Server/Client, ReportCaster, Dev Studio: 7.6.11
Resource Analyzer, Resource Governor, Library, Maintain, InfoAssist
OS: Windows Server 2003
Application/Web Server: Tomcat 5.5.25
Java: JDK 1.6.0_03
Authentication: LDAP, MRREALM Driver
Output: PDF, EXL2K, HTM

------------------------------------
Databases:
------------------------------------
Oracle 10g
DB2 (AS/400)
MSSQL Server 2005
Access/FoxPro
June 20, 2012, 03:35 PM
Kevin W
I've also used the technique of filling a dynamic parameter drop down with dates selected from the data source. Then make them pick from those.


WebFOCUS 7.7.05 (Someday 8)
Windows 7, All Outputs
In Focus since 1983.