To compare two user entered dates
HI FRIENDS
here is my code. When i try to print the user entered date (dd/MM/yyyy)(which i am storing in a string) the program dispalys nothing. and everey time i enter a valid date it displas "invalid From date entered ". I need to store the user entered date into a string because i need that for further use. All my intesion is to get two dates from user in dd/MM/yyyy. Strore them in certain variable. Check if they are valid or not. and make sure todate is either equal or greater than fromdate. Please help me to solve this problem.
public class EDTDateValidation extends JFrame implements ActionListener{
private JLabel fromlabel;
private JLabel tolabel;
private JTextField fromtxt;
private JTextField totxt;
private String fmt ="dd/MM/yyyy";
private java.lang.String fromdate;
private java.lang.String todate;
private JButton buttonOK;
private JButton buttonCancel;
private Date theDate;
private Date date1;
private Date date2;
private JPanel mainPanel;
SimpleDateFormat dtformat = new SimpleDateFormat(fmt);
public EDTDateValidation(){
super("Date Validation");
dtformat.setLenient(false);
mainPanel=new JPanel();
mainPanel.setLayout(null);
fromlabel = new JLabel("From Date");
tolabel = new JLabel("To Date");
buttonOK = new JButton("OK");
buttonCancel = new JButton("Cancel");
fromdate = new String();
todate = new String();
fromtxt = new JTextField(10);
totxt = new JTextField(10);
fromdate = fromtxt.getText();
todate = totxt.getText();
mainPanel.add(fromlabel);
fromlabel.setBounds(20,20,50,15);
mainPanel.add(tolabel);
tolabel.setBounds(20,50,50,15);
mainPanel.add(fromtxt);
fromtxt.setBounds(90,20,130,20);
mainPanel.add(totxt);
totxt. setBounds(90,50,130,20);
mainPanel.add(buttonOK);
buttonOK.setBounds(70,80,71,23);
mainPanel.add(buttonCancel);
buttonCancel.setBounds(150,80,71,23);
buttonOK.addActionListener(this);
buttonCancel.addActionListener(this);
setContentPane(mainPanel);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(247,140);
setResizable(false);
//pack();
public static void main(String args[]) {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
catch(Exception e) {
System.err.println("Could not load Look and Feel" + e);
EDTDateValidation edtDateVal = new EDTDateValidation();
edtDateVal.setVisible(true);
public void actionPerformed(ActionEvent e) {
if(e.getSource() == buttonOK){
System.out.println(fromtxt.getText());
// System.out.println(SimpleDateFormat.format(fromdate));
System.out.println(fromdate); //THIS DISPLAYS BLANK
System.out.println(todate); //THIS ASWELL
try {
Date date = null;
date = dtformat.parse(fromdate);
System.out.println("valid From date entered!");
catch(Exception f) {
System.out.println("Invalid From date entered!");
// textField1.setText("");
return;
try {
Date date = null;
date = dtformat.parse(todate);
System.out.println("valid TO date entered!");
catch(Exception f) {
System.out.println("Invalid To date entered!");
// textField1.setText("");
return;
}
Judging from your code, you've got a lot of learning
to do. I suggest you
split it up:
1. Write non-GUI code that attempts to parse, compare
and format dates.
2. Write simpler GUI code to capture ordinary
strings, for example, and
worry about dates after you can do something simpler.And standard instructions: Use code tags.
Similar Messages
-
Calculate one month prior to user entered date by a Date/Time field
Hi All,
I am currently pretty new to Live cycle and have no idea about Java scripting, i have been using this site a lot for my forms and have used the FormCalc for expanding tables and so on but this one is proving difficult. I am currently designing a form that requires a calculation of one month prior to a user entered date by a Date/Time field. I have looked at multiple posts on how to do this but none have worked (they are using the Date2Num).
Is anyone able to enlighten me please?
I currently have:
Date/Time field Date Due
Date/Time field Planned Date of Review
I need Planned Date of Review to be calculated to be 30 days prior to Date Due. How do I go about doing this? Is it incorrect to use a Date/Time field as the field type for the calculation?
Cheers
BradYou can use FormCalc to compare the user input.
Put this script into the exit:Event of the date field.
if (Date2Num($.formattedValue, "MM/DD/YYYY") ne date()) then
$host.messageBox("The entered date is not todays date!")
endif -
How can I read the last cell of a JTable that a user Enters data
I have a one column JTable with several rows that a user enters data to. Upon entering the last data, the user clicks a button to read all the data from the rows in the JTable and puts them in an arraylist. If the user does not click enter or navigates away from the last cell, then after clicking the button it does not read the last cell entered. Since the user is clicking on a button to indicate he is done entering data on the table, does he also have to hit the enter key to indicate he is done entering the data?
The code below is my tablemodelListener:
public class InteractiveTableModelListener implements TableModelListener {
public void tableChanged(TableModelEvent evt) {
if (evt.getType() == TableModelEvent.UPDATE) {
int row = evt.getFirstRow();
System.out.println("Update row:"+" "+row);
jTable1.setRowSelectionInterval(row, row);
}Don't forget to use the Code Formatting Tags so the posted code retains its original formatting. That is done by selecting the code and then clicking on the "Code" button above the question input area.
In the future, Swing related questions should be posted in the Swing fourm. (This question has been asked and answered dozens of times).
But there is not need to repost because [Table Stop Editing|http://www.camick.com/java/blog.html?name=table-stop-editing] explains whats happening and give a couple of solutions. -
Cell data not getting refreshed in which user enters data OO ALV(editable)
Hi Friends,
I am using OO ALV for editable grid display.
I am unable to change grid data in the cell in which user enters something, using OO ALV. Did through debugging of my own program and found that some problem with system program. Then I did all system debugging. Could not find out why is the grid not getting refreshed with the new data in the cell in which user had entered some value. Rest of the cell's data are getting refreshed with the values which i am updating in the final internal table. I can see that the data in the final internal table is changed for the cell in which user enters data. But even after the call of
CALL METHOD obj_alvgrid1->refresh_table_display
does not refreshes the data in the cell in which user had entered data. Rest of the cells data are getting refreshed.
Piece of code:
SET HANDLER obj_event_receiver->handle_data_changed
FOR obj_alvgrid1.
METHODS: handle_data_changed
FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed
e_onf4
e_onf4_before
e_onf4_after.
METHOD handle_data_changed.
DATA : v_valid TYPE char1,
v_refresh TYPE char1.
*--check mt_good_cells semantically
CALL METHOD perform_semantic_checks( er_data_changed ).
*--If PBO is again visited, just refresh the ALV grid.
CALL METHOD obj_alvgrid1->refresh_table_display
EXCEPTIONS
finished = 1
OTHERS = 2.
IF sy-subrc <> 0.
EXIT.
ENDIF.
ENDMETHOD.
METHOD perform_semantic_checks.
LOOP AT er_data_changed->mt_good_cells INTO w_good.
v_index = sy-tabix.
CASE w_good-fieldname.
WHEN 'ZASCAS'.
*Now here based on some conditions I am changing my final internal table i_zamtsmatnp
MODIFY i_zamtsmatnp FROM w_zamtsmatnp INDEX
w_good-row_id TRANSPORTING
zascas modif.
User enters data in zascas field. Based on the data entered, I am changing other fields which is getting refreshed. I am also changing zascas in the program even after user had already entered the value which was bit wrong and i am correcting it in the program on the even "data_changed" even.
Please help me friends as i m strugling past hours wondering why the data is not getting refreshed for the cell in which user enter data.
Regards,
SuryaHi Surya,
The approach you are following is correct. You need to use the comibnation of all these things:
Event - DATA_CHANGED
Methods - CHECK_CHANGED_DATA
- GET_CHANGED_DATA.
However, here are few standard programs which are having similar functionality.
BCALV_EDIT_03
BCALV_EDIT_07
Check out these once.
Note: If anything is helpful, dont forget to reward points
Thanks,
Adithya K
SAP Practise
[email protected] -
How to use User entered dates in intreval
Hi,
User will enter date range in variable
As per my requirment i want to use no of days between those 2 user entered dates in my calculaction
How can i achieve this at report level.
ThanksHi
Create a variable with intreval.
There is a function module which calculates the no of days between the days
Go to SE38 and ZXRSRU01 Program
Write the Code like this (Not exact code) you can modify
WHEN "ZZZZZ"(Before that create a formula variable to get the number of days between the days and use the tech name of the formula variable here)
read ..the lower limit and the upper limit of the caldaz variable
FROMDATE = L_S_RANGE-low
TODATE = L_S_RANGE-HIGH
Then call the function module
Search for the function module by using days in SE37
Then pass the from and to Date to the function module it will retun the number of days
update that to table e_T_Range
You can proceed with this
Regards
M.A -
How to get the user entered data?
Hi all,
I have created an HTMLB DynPage component.
In That i have created my input screen with textboxes using response.write method.
i have added one onConfirm event on which the data whould validate.
so onConfirm method im trying to get the data with request.getParameter method which returns null...
how to do...how to get the user entered data to do my validations...can anyone plz advice.
Thanks,
ViswesHi
inputfield or textbox component entered directly using response.write(...) are not htmlb , but html.
to create portal input field (ie HTMLB), you should do something like
this in the doProcessBeforeOutput member function
InputField field1 = new InputField("Id1");
field1.setSize(8); // 8 characters
this.getForm().addComponent(field1);
and in doProcessAfterInput member function
InputField field1 =
(InputField) this.getComponentByName("Id1");
you can then manipulate the content of the field.
Hope this help,
Guillaume -
How to populate date & time when user enter data for custom table in sm30
Can anyone tell me How to populate system date & time when user enter data for custom table in sm30..
Req is
i have custom table and using sm30 user can enter data.
after saving date i want to update date & time in table
Pls let me know where to write the code?
Thanks in AdvanceYou have to write the code in EVENT 01 in SE54 transaction. Go to SE54, enter your Ztable name and in the menu 'Environment-->Events'. Press 'ENTER' to go past the popup message. In the next screen, click on 'New Entries'. In the first column, enter 01 and in the next column give some name for your routine(say UPDATE_USER_DATE_TIME). Then click on the souce code icon that appears in blue at the end of the row. In the code, you need logic like below.
FORM update_user_date_time.
DATA: f_index LIKE sy-tabix.
DATA: BEGIN OF l_total.
INCLUDE STRUCTURE zztable.
INCLUDE STRUCTURE vimtbflags.
DATA END OF l_total.
DATA: s_record TYPE zztable.
LOOP AT total INTO l_total.
IF l_total-vim_action = aendern OR
l_total-vim_action = neuer_eintrag.
MOVE-CORRESPONDING l_total TO s_record.
s_record-zz_user = sy-uname.
s_record-zz_date = sy-datum.
s_record-zz_time = sy-uzeit.
READ TABLE extract WITH KEY l_total.
IF sy-subrc EQ 0.
f_index = sy-tabix.
ELSE.
CLEAR f_index.
ENDIF.
MOVE-CORRESPONDING s_record TO l_total.
MODIFY total FROM l_total.
CHECK f_index GT 0.
MODIFY extract INDEX f_index FROM l_total.
ENDIF.
ENDLOOP.
ENDFORM. " UPDATE_USER_DATE_TIME
Here ZZTABLE is the Z table and ZZ_USER, ZZ_DATE, and ZZ_TIME are the fields that are updated. -
User entered date to be calculated for another header
Hello All,
In a BEx query, a user enters a date (date1), and I need to display Date1 - 30 as a header for one of the columns. Can I take care of this while creating a text variable??
Or I need to use a customer exit with i_step = 2?
Kindly inform..
Eg: User entered date : 30-Jan-07
The header should be like Non moving stock as of 1-Jan-07
Thanks in advance.
Regards,
K2Hello Prasad,
Can I try offset for a Text variable created for the header??
Thanks.
Regards,
K2 -
Display of user entered date in one column
Hi Guys,
Is it possible to display user entered date(any date) in column of all rows?
I need to calculate no of days(User entered date-Deposit date).
Please give some input.Hi Sagar,
How can u display user enterd date in a column?
For example if user entered 31.03.2007 as input,i need the same date(31.03.2007 ) to display in all rows of the column,so i can use it in the formula.
Thanks. -
Show user entered date when ssrs report exported to csv format
Hi All,
How can I show date range parameter entered by user when ssrs report is exported to csv format.
my csv output should look like this....
Date : 01/01/2015 TO 01/31/2015 (user selected dates)
ID,EmpFirstName,EmpLastName,Location
1,Tom,Garry,NY
2,John,Graham,NJ
3,Ron,Lorrie,CA
Thanks,
RH
sqlHi RH,
You can add two textbox at the top outside the tablix and using expression to get the parameter value use have selected to display in the textbox as blew:
TextBox1: =Parameters!Date.Value
TextBox2: =Parameters!To.Value
For Multiple value parameter you can use the expression like : =Join(Parameters!Date.Value,",")
You can rename the two textbox' name in the properties as "Date" and "To" then the two textboxs will display like belkow in the CSV report:
Date TO
01/01/2015 01/31/2015
ID EmpFirstName EmpLastName Location
1 Tom Garry NY
2 John Graham NJ
3 Ron Lorrie CA
If you still have any problem, please feel free to ask.
Regards
Vicky Liu
Vicky Liu
TechNet Community Support -
Text Varible for user enter date range
Hi,
I need code for text variable,
the user enters the date range in user entry varible screen
ex : production for the date range of xxxxx(xxxx= text variable)
user enters the date range 25-05-2010 - 31-05-2010
The query description name should be
production for the date range of 25-05-2010 - 31-05-2010
for that i need code i _step 2 code
User eners the date range in varaible screen as per that report header has to come
Please provide the valuble code.
Thanks & Regards,
SathishUse Replacement Path Approach instead of Customer Exit.
Create two Text variables TVAR1 and TVAR2 of type replacement path. Replace them with the Date Characteristic that you are using on which variable is created for user to enter the date range.
While creating Text variables, for TVAR1 select From Value and TVAR2 select To Value.
Now make the Query description as Production for the date range of &TVAR1& - &TVAR2& -
How to handle user entered data validation
Hi,
In my page i have three fields
Empname (String)
Empnumber (Number)
DOB (Date)
These fields are mapped to VO which are mapped to EO.
When user enters string in Empnumber field then it will throw user following Error "Cannot create an object of type:oracle.jbo.domain.Number with value hghfg"
I want to display above Error in user friendly fashion.
Where to do this and How to do this?
And i have one more question
can we handle all the exceptions in seter method of EOIMPL?
-Thanks
MithunSumit,
I have set 'Disable Client Side Validation' in the property inspector true for submit button. Added below code for validation
In CO
String lb_flag= (String)am.invokeMethod("validateRVSize",prm1,prmType1);
In AM
public String validateRVSize(String val)
String values = "1234567890' ";
for (int i=0; i < val.length(); i++)
if (values.indexOf(val.charAt(i)) < 0)
return "false";
return "true";
but what i have observed is control is not at all coming to process form request. it is doing it's validation in processformdata itself, i suppose.
because no statement is getting printed if i had entered characters in number field.
-Mithun -
How can a user enter data as many it was specified for??
I am writing a program that makes calculations on data entered by the user. First I ask the user how many inputs he/she wants. And my problem is how the user can enter as many input he/she asked for. How do I make the program ask for input more than once, before I do calculation on the entered data???
I am sorry if my english is hard to understand, but I hope this was understandable.I think you should use a readInt() if you have such a method in your Keyboard class to ask for the numbers.
Then create a float array with that many elements, and use the for-loop you have shown:
for (...) {
numbers[ i-1 ] = Keyboard.readFloat(); // numbers is a float array
// if you let i go from 0 to i < tall, then you don't need to subtract 1 from i.
} -
How to get 1 day less than user entered date
Hi
There is a user entry for date. If the user enters 20060427 then the report should run for 20060426. I tried giving 'LT' in the CMOD code. But it gives an error. Can anyone pls help. Is there a function module for this?
Thanks
SujaHi Suja,
You can use Less Than and Greater than for a user entry variable as follows: When you right click > restrict the char, then in the pop up box there is a drop down for Selection. Choose Value Hange here. Then in the drop down to the right you will have values ike Between, Less Than, Greater than...you can select as required.
Hope this helps... -
How to compare user entered date with current date
Hi all
my requirement is, user allowed select one date, in code i have compare this date with current day date. it should be 15days gap other wise display error message.
I am worried about how to get current date in code. Is there any code to get current date. please reply me with code or mail me at [email protected]
Thanx
keerthiKeerthi,
Use the method <b>getDifference()</b> of the DateHelper.java available here.<a href="http://www.koders.com/java/fid14A61FEB1B45A64E42E1DCAD7070B46AE46340BA.aspx">DateHelper</a>
1. Create a new folder, say Util under your src folder. (com.xyz.util)
2. Put this DateHelper.java file in that folder,(com.xyz.util) .
3. Now, write an import statement for this java class in the required view.
4. Use the getDifference() method of this class to the difference in days between two days.
Or
Simply use this code.
// Get msec from each, and subtract.
long diff = currDate.getTime() - selectedDate.getTime();
int noOfDays = diff / (1000 * 60 * 60 * 24);
where currDate is today's Date and selectedDate is the Date selected by the User.
Bala
Maybe you are looking for
-
COPA - Split of Value from condition type into different value fields
Dear All, Customer is having several free schemes to customer the same is set up by SD and Cost of free goods is attached to One Z condition type, this flows along with Main product as characteristic. So we have Main product cost in VPRS and Scheme c
-
Source agent: FM 9.0p250, unstructured Transformative agent: RH 8.0.2.208 OS: WinXP Pro V. 2002 SP3 CPU: Core2 Quad @ 2.4 GHz RAM: 3.25 GB Free Space: 12.6 GB File Sys.: NTFS Swap: D & E (system-managed) Is anyone else experiencing problems wi
-
Any Tips for editing Live Event 2 camera shoot?
I need to quickly edit a 2 DV camera recording of a live multi-scene performance (duration of 90 minutes), with audio additionally recorded on a good quality remote mic. I have used FCE for some time, but not for several months. I have managed to for
-
The latest version of I-tunes would not completely install. The progress bar would go out to about the last 1/4inch and stay there all night. We have a one year old I-Mac
-
Calendar subscriptions not showing up in mountain lion notification centre
Has anyone else had this problem when your calendar subscriptions are not showing up on the notification centre. Everything seems to be turned on in the preferences but I'm not seeing any of my calendar subscriptions entrys showing up in the notifica