How to set up GUI date input to retain format look and feel - swing

Okay I've tried this a few different ways and haven't been able to get it to do what I want it to. I've also visited this page: http://www.exampledepot.com/egs/javax.swing.text/formtext_FormTextDate.html
I have a spinner:
SimpleDateFormat datePattern = new SimpleDateFormat("MM/dd/yyyy");
JLabel endLabel = new JLabel("End Date: ");
JSpinner endSpinner = new JSpinner(new SpinnerDateModel());
endSpinner.setEditor(new JSpinner.DateEditor(endSpinner, datePattern.toPattern()));
This automatically loads today's date. I would prefer it to just show MM/DD/YYYY within the actual gui. This would give it the look of being date input without requiring a specific date to be entered if not required. Then as soon as you start spinning it would take a date. I can't seem to figure out how to do this. Any suggestions? I've also started looking up FormattedTextFields as well as an option. Would this be a better route to go?
If so, how can I set up the FormattedTextField to look like this: [ / / ]. Then when you put input in, keep that format, requiring only digits and 2 digits for month, 2 digits for day, and 4 digits for year. I would assume I'd have to set up some sort of pattern instead of initializing the FormattedTextField as a date? For example:
JFormattedTextField date = new JFormattedTextField(new SimpleDateFormat("MM/dd/yyyy"));
date.setValue(" / / ");
But all you would have to do is clear out the field and it would no longer look like a date. I want it to at least keep the '/' no matter what you do.
Sorry for the long drawn out question.

Related

Need a proper input mask for a time field in Microsoft Access

My table field is date/time and formatted like this:
mm/dd/yyyy hh:nn:ss
I want the user to see this (with the space appearing between date and time
__/__/__ __:__:__
I want an input mask that demands:
Either 1 or 2 digits for the month
Either 1 or 2 digits for the dat
All 4 digits for the year
SHOWS the space but just jumps over it for the user
Either 1 or 2 digits for each of Hours, Minutes and Seconds
Further, when setting up a DB, is it just smarter to have two separate fields for Date and Time. A collegue encouraged me to break them out ... seems sensible?
00/00/0000##00:00:00
See the outcome in the image
Controlled user input is not an easy task in Access, as it is optimised for the opposite: To be tolerant and accept many input sequences for date and time.
For the cases where controlled input is mandatory, I've written two articles including full code (too much to post here) and demo, that may give you some ideas:
Entering ISO formatted date with input mask and full validation in Microsoft Access
Current code at VBA.DateEntry.
and
Entering 24-hour time with input mask and full validation in Microsoft Access.
Current code at VBA.TimeEntry.

Converting timer format hh:mm to decimal format hh.decimal(mm) in Business Objects

The aim is to create a new data column based on a current time formatted colum.
For example I want to have 4:20 -> 4.33. I can't find a way of manipulating the time format to extract the hours and minutes seperatly to use hours + (minutes / 60).
Any help appreciated. Thank you.
To pick specific parts out of a datetime object you need to use the FormatDate() function. It returns a string which you need to convert to a number with the ToNumber() function before adding the hours and minutes together. So let's create a few variables...
Current DateTime=CurrentDate()
Hours=ToNumber(FormatDate([Current DateTime];"hh"); "##")
Minutes=ToNumber(FormatDate([Current DateTime];"mm"); "##")
Hours Minutes Decimal=[Hours] + ([Minutes]/60)
If you want to put this all together in one variable you can certainly do that...
Hours Minutes Decimal All in One=ToNumber(FormatDate(CurrentDate();"hh"); "##") + (ToNumber(FormatDate(CurrentDate();"mm"); "##")/60)
To locate documentation on what values correspond to which parts of the datetime value do the following...
Navigate to the FormatDate() function in the Variable Editor.
Click on "More on this function" in the lower right corner.
Click on "Custom Formats"

get difference between 2 dates in google script

I'm trying to get the difference between the 2 dates in googlescript. However it doesn't seem to be working. Does anyone seem to know why? My user defined variables are working it's just when i get the difference between the 2 the result is like 4.28E8 whereas the answer is supposed to be like 40. Is there a way to convert the date into a number then convert it back into a date?
ddate = output.getRange(lRow2,2,1,1).getValue() - output.getRange(2,1,1,1).getValue()
Function works, its just the difference is in milliseconds. For those interested in the conversion, it's as follows:
diff = ((output.getRange(lRow2,2,1,1).getValue() - output.getRange(2,1,1,1).getValue()) / (1000*60*60*24))
or simply:
days = milliseconds/ (1000*60*60*24)

Access Report Show # instead of Date

My access report is showing ##### instead of showing the datetime value in the row. When I clicks on it the ##### turn outs to the actual date as if it was hidden behind it. I have tried changing the date format to Long Date Medium Date and Short Date in both the related table as well as in the report's Format properties but is it not working at all.
Why is it so?
The problem you have can be because there's no enough space in the textbox (or other control) to display the value you need.
You can solve this by either increasing the size of the control or decreasing the size of the font you are using.
An alternative can be to convert the value you want to display into a string. Since you are dealing with dates, I sugest you use the format$() function. For example:
=format$([yourDateField],'yyyy-mm-dd')
will return a date in the year-month-day format. Check the online help to know more about this function.
Hope this helps you

Can I create Date entry control with date separator for classic ASP

I was using a calendar control for entry of date in a classic-ASP application. But calendar control is not keyboard friendly and take more time for data entry. So later I added a simple text box with date validation. It works fine. However, the user need to put the date separator also. I wish to put a date entry field that comes with a pre-configured date format and separator, so that the user simply type on the numbers and the field cause a validation as well.
How can I achieve this?
Just use jQuery/javascript to mask the date text field. It will automatically format the date as the user enters the values. Also forces correct validation as it works.
for example jQuery plugins search for :
jquery date mask: http://digitalbush.com/projects/masked-input-plugin/
You can always put three text boxes with the separator as text (as I do in an old ASP classic site)
You need to separate the date in the response and then join it using DateSerial when posted.
When we've created something similar in the past we've allowed the user to enter a date into a textbox in a couple of different ways:
DDMMYYYY
D/M/YYYY
0 (for today)
When the form is submitted we had a simple ASP function to convert DDMMYYYY into DD/MM/YYYY (date string must be 8 characters though because the assumption was 2 digits for DD, insert the separator, 2 for MM, etc.) and check this was a valid date, and an if formdate = 0 then formdate=now() rule.
You need to add some JavaScript validation on the form too though. On the textbox add an onblur event to check for the same things - either 8 digits entered, or a valid date, or a 0 - otherwise alert the user. (I would do this in jQuery if we were redoing it today)
You can get quite helpful with the Javascript "validation" to speed up data-entry if you wanted to, for example if a lot of dates being entered are yesterday or tomorrow allow a -1 or +1, or if data entry is always for the current month but a different day, allow the user to just enter a number - 15 and the Javascript/jQuery converts the string to 15/03/2011.
With HTML 5...textMode="Date"
<asp:TextBox ID="TextBoxDate"
runat="server"
CssClass="form-control" Width="561px"
TextMode="Date">
</asp:TextBox>