Determine Date field format dynamically
Hello friends,
I'm writing some database access code in java. The biggest problem I face is date fields. Because I don't know the date field format (For example, in SQL Sever we can have dd/mm/yy or mm/dd/yy, etc), I can't format dates for insert/update statements.
Is there a way to determine the date field format dynamically? Regardless of database, for ex. MS SQL, Oracle?
Thank you.
Hey!
There is a way to do this! The Oracle Database understands SQL92 Syntax. So you can use
- {d ?yyyy-mm-dd?} for date representation,
- {t ?hh:mm:ss?} for time representation,
- {ts ?yyyy-mm-dd hh:mm:ss.f...?} for timestamp rep.
Here is a small example:
// Connect to the database
// You can put a database name after the @ sign in the connection URL.
Connection conn = DriverManager.getConnection
("jdbc:oracle:oci8:@", "scott", "tiger");
// Create a Statement
Statement stmt = conn.createStatement ();
// Select the ename column from the emp table where the hiredate is Jan-23-1982
ResultSet rset = stmt.executeQuery
("SELECT ename FROM emp WHERE hiredate = {d ?1982-01-23?}");
// Iterate through the result and print the employee names
while (rset.next ())
System.out.println (rset.getString (1));I hope this is what you wanted to know!
Similar Messages
-
Hi All,
I'm back already! Learning Flash is beginning to get to me
again so I returned for yet more help!
I've written the following AS code to get tomorrow's date . .
// Calculates today's date and tomorrow's date
var dToday:Date = new Date();
dToday.getDate()
trace("today: " + dToday) //today's date
myD = dToday.getDate() + 100; // plus one day
var dTomorrow:Date = new Date();
dTomorrow.setDate(myD)
trace("new: " + dTomorrow) //tomorrow's date
var strDate:String = new String();
var strDate = String(dTomorrow);
trace("String: " + strDate);
The strDate string returns the following value . . . "Tue Jul
11 16:19:57 GMT+0100 2006".
That is all well and good but I want to convert it into the
following format for comparison with another field . . .
"200607111619" which is basically the same value in the following
format . . . "yyyymmddhhmm".
Does the only way of doing this involve using parsing logic
to break down the original string and then reconstruct it in the
required format using variables from the broken down original
string?
I have tried looking at the Date Field object notes in my
book but it does not give me anything as regards this programming
requirement. The only thing I can find that might suit this purpose
is string parsing logic. Am I right or is there an easier way to
set a date field format?
Any help would as always be much appreciated!
Thanks,
Kevin.I'm working on an application which requires a valid Voucher
Number to proceed. The Voucher number is based on a combination of
'date/time/no of items' (e.g. 20060711095802 which is today at
09:58 (on a 24 hr clock) for 2 (02) items).
As this date this date/time Voucher Number logic is
essentially sequential, in that each subsequent Voucher Number will
be greater than the last good known Voucher Number entered into the
application (which is already stored in a variable field for
comparison). But it must also be less than tomorrow's date, for
which the Voucher Number would always be tomorrow's date (e.g.
20060712 at 00:00 hrs for 00 items, thus giving 20060712000000).
This is the value that I'm trying to ascertain from the date field
logic.
It would thus be really handy for comparison if I could just
format tomorrow's date and time in the format yyyymmddhhmm and just
add '00' to the end of the string.
I don't like the idea of using the milliseconds value as it
will be necessary then to convert the Voucher Number entered to a
date field for comparison. -
Browser date field format in header
I am using Browser 2.0 for some ad hoc queries on an Oracle
7.2.3 database.
My client is running Windows NT 4.0 with Service Pack 4.
Regional settings are set to English (Australia).
The page setup in Browser allows you in the header or footer to
insert the a date field via "&d". Documentation states this is
system generated.
However, in the print preview and print out the date is
formatted as MM/DD/YY. I need to have it formatted as DD-MON-
YYYY.
Can anyone suggest to me from which system the format is being
generated or any
suggestions on how to change it in.
Thanks
nullcan you paste the timestamp being displayed?
You can use, format-date function or other, but its all based on the data you have for DATE. -
Hi,
I'm trying to import some UDF information into Business Partners, but one of my UDFs is set up as a Date field. What format of date shoul be in the import file becasue DD/MM/YYYY doesnt import so I tried YYYY/MM/DD and this doesnt work either.
Thank you xHi,
Check this thread.
Re: defining date possible while doing DTW import to Goods Receipt
regards,
Fidel -
Conversion of date field format from char to dats
Hi All,
one issue with Date field.
in my internal table i have a date field with type char(10).
But when I upload the data to database through upload program, there I have a date field with type "DATS".
how do I convert and store it in "DATS " format in database.
please help...HI ,
Try this use CONVERT_DATE_TO_INTERNAl
CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
EXPORTING
date_external = "ur date from file
ACCEPT_INITIAL_DATE =
IMPORTING
DATE_INTERNAL = "( date in dats format )
EXCEPTIONS
DATE_EXTERNAL_IS_INVALID = 1
OTHERS = 2
IF sy-subrc <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. -
The data field format for the sql* loader
the data field in my data file was surrounded by ",", such as "1","2","3",...
so in my control file, I coded
fields terminated by ',' enclosed by '"'
no error after I execute sqlldr command.
however, on data has been inserted into table either.
if I remove "" and ,
the data field changed to 1 2 3 ...
and the data has been inserted into my table
However the first format is what I want. can anyone experienced silmilar situation? please give me a hint.
your help is highly appreciated
null<BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Renali ():
say:
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' TRAILING NULLCOLS (
colname1,
colname2,
colname3)
the data field in my data file was surrounded by ",", such as "1","2","3",...
so in my control file, I coded
fields terminated by ',' enclosed by '"'
no error after I execute sqlldr command.
however, on data has been inserted into table either.
if I remove "" and ,
the data field changed to 1 2 3 ...
and the data has been inserted into my table
However the first format is what I want. can anyone experienced silmilar situation? please give me a hint.
your help is highly appreciated
<HR></BLOCKQUOTE>
null -
IDoc posted in R/3 but data for Date field has not generated.
Hi Experts
This is JDBC to IDoc scenarion.
Source: MS SQL Server
Date Data Type: smalldatetime
Date field Format: yyyy-MM-dd hh:mm:ss --> example: 2009-11-13 00:00:00
XI Mapping: Source Date --> Transformation --> Target Date
Transformation: yyyy-MM-dd hh:mm:ss to yyyyMMdd
Target: R/3 System
Date Data Type: ERDAT from VBAK table - Date on Which Record Was Created
Date field Format: Date field (YYYYMMDD) stored as char(8)
Check points:
1. Mapping is working fine in XI and transformation is done with the test data: 2009-11-13 00:00:00 --> to ---> 20091113
2. In SXMB_MONI the data is processed from the source and the IDoc XML data is generated. In the IDoc XML data the date field is containing the value <DATE>20091113</DATE>
3. But when I tried to open the IDoc(SE05) in R/3 the date field is empty and no data is generated.
Request you to let me know why the error is happening.
Regards
RamHi Ram,
First try to test the same IDOC generated in ECC Box by populating date field value using WE19 and test .
Or
Instead of passing date value from SQL Server, Just give a try with Current Date function in Mapping and test in ECC system.
then we can think on further analysis.
Regards,
Vijay -
In BDC programming how can we maintain date field
hello all
In BDC programming how we will deal with date field?
In my flat file my date field format is different from the sap date field format. how can we deal this?hi,
just define a variable with length 10 in ur internal table.
now pass the date format in flat file as dd.mm.yyyy. -
Abap date field and calendar in iView
When I create an iView out of a transaction which has a date field,the iView cannot display the calendar in the portal.Just an Empty dialog box appears in place of the calendar.
Please help.
regards,
BhupeshHi,
that's quite easy to realize with FormCalc.
In you date fields exit event add the following code:
textField1 = Num2Date( Date2Num($.formattedValue, "MM/DD/YYYY"), "YYYY")
Note: This sample assumes that your date field formats the date with "MM/DD/YYYY". You may have to change the pattern to make it work at your end. -
Extract Year (only) from Date Field and Display in Text Field
I need to extract the year from a user entered date field and display the year in a text field. Can someone help me with the correct script to do this?
Hi,
that's quite easy to realize with FormCalc.
In you date fields exit event add the following code:
textField1 = Num2Date( Date2Num($.formattedValue, "MM/DD/YYYY"), "YYYY")
Note: This sample assumes that your date field formats the date with "MM/DD/YYYY". You may have to change the pattern to make it work at your end. -
Dynamic action with set value on date field
Hi,
I'm using APEX 4.02
I'm trying to calculate the age based on the date of birth dynamically on a form. I'm trying to do this with a (advanced)dynamic action with set value.
I'm able to get this kind of action working based on a number field etc, but NEVER on a date field.
I've read all posts on this subject but so far no solution. Even if I try to simply copy the value over to another date field or typecast it to a string ( to_char function ) it does not work. So for me the problem seems to be in the source field being a date field.
I've tried using the source value as is in a select statement :
select :P33_GEBOORTEDATUM from dual;
and also type casted based on the date format :
select TO_DATE(:P33_GEBOORTEDATUM,'DD-MON-YYYY') from dual
but still no luck.
On the same form I don't have any issues as long as the calculation is based on number fields, but as soon as I start using dates all goes wrong.
Any suggestions would be greatly appreciated. If you need any extra info just let me know.
Cheers
Bas
b.t.w My application default date format is DD-MON-YYYY, maybe this has something to do with the issue .... ?
Edited by: user3338841 on 3-apr-2011 7:33Hi,
Create a dynamic action named "set age" with following values.
Event: Change
Selection Type: Item(s)
Item(s): P1_DATE_OF_BIRTH
Action: Set value
Fire on page load: TRUE
Set Type: PL/SQL Expression
PL/SQL Expression: ROUND( (SYSDATE - :P1_DATE_OF_BIRTH)/365.24,0)
Page items to submit: P1_DATE_OF_BIRTH
Selection Type: Item(s)
Item(s): P1_AGE
Regards,
Kartik Patel
http://patelkartik.blogspot.com/
http://apex.oracle.com/pls/apex/f?p=9904351712:1 -
Name_in(date field) is converted in which format
using name_in with a date parameter is automatically converted to dd-mon-yyyy character format. How to change this returning format?
Can you please give us some more information . I mean elaborate your question
using name_in with a date parameter is automatically converted to dd-mon-yyyy character format. How to change this returning format?
in my library
IF par_param_block IS NOT NULL THEN
GO_BLOCK(par_param_block);
ls_first_item := par_param_block||'.'||NAME_IN('system.current_item');
ls_current_item := NAME_IN('system.current_item');
--Dynamically get parameters from PARAM block (from forms)
--pass on ITEM NAME / ITEM VALUE in (From the PARAM block into the sy_print form - as parameters !!!!)
i := 0;
LOOP
IF GET_ITEM_PROPERTY(par_param_block||'.'||ls_current_item, ITEM_TYPE) IN ('LIST', 'TEXT ITEM', 'RADIO GROUP', 'CHECKBOX') THEN
i := i + 1;
ADD_PARAMETER(pck_report_pl, 'PL'||i, TEXT_PARAMETER, ls_current_item);
ADD_PARAMETER(pck_report_pl, 'PV'||i, TEXT_PARAMETER ,
NAME_IN(par_param_block||'.'||ls_current_item));
--- for date fields the name_in returns the date in this format dd-mon-yyyy ----
END IF;
NEXT_ITEM;
ls_current_item := NAME_IN('system.current_item');
EXIT WHEN ls_first_item = par_param_block||'.'||ls_current_item;
END LOOP; -
Date/Time field format not wysiwyg
I have a date field in my form that I formatted as m/d/yyyy hh:mm. I thought that because it formats that field in that way my script would get passed down that way however it is not. I want to manipulate it so the value is in the format I want it to be....
I enter this in the date/time field: April 1, 2011 1:40PM
When I click out of the field and I see: 4/1/2011 13:40
Then I have a script that uses this field to make the file name but because I have a comma in there it will not save, if I take the comma out it will save. So the main question is how do I format my field to pass down the value that I am seeing not the value that I am typing in. You will notice I have a replace in there but I can't account for the comma because it reads it as part of the syntax.
// Get the field value
var dtentered = getField("datetime").value;
//replace any odd characters that will not allow the file to save
var fdt = dtentered.replace(/[!@#$%^&*()+=|\:;"'<>?/{}]/g,"_");
// Specify the folder
var fldr = "/c/WO Completed/";
// Determine the full name and path
var fp = fldr + fdt + ".pdf";Thanks for the response...I'm not sure that I understand what you mean back-slash...I went ahead and did this but now it is giving me an odd file name
// Get the field value
var dt = getField("datetime").value;
var mydt = escape(dt);
//replace any odd characters that will not allow the file to save
var fdt = mydt.replace(/[!@#$%^&*()+=|\:;"'<>?/{}]/g,"_");
// Specify the folder
var fldr = "/c/WO Completed/";
// Determine the full name and path
var fp = fldr + fdt + ".pdf";
Returns a file name as
April_201_2C_202011_201_3A40PM.pdf
I was looking more for
4_1_2011_13_40.pdf
or
April_1_2011_1_40PM.pdf -
How to display date field in ALV in format 'YYYY-MM-DD'?
Hi experts,
I am not getting displayed the date field in ALV in the format 'YYYY-MM-DD' if it is different than my user setting's format (DD.MM.YYYY).
Tried with the edit mask
LVC_S_FCAT-EDIT_MASK = '____-__-__' but it does not work.
I could not find the conversion routine for this. Is it possible to write customer conversion routine?
I have to use DATE field, otherwise if I display this format in CHAR10 field , sorting in ALV does not work for this field.
PLEASE ANY HELP!
Kind regards,
DanijelaHi,
Use FM FORMAT_DATE_4_OUTPUT.
TYPE-POOLS : slis, KKBLO.
TYPES: BEGIN OF t_data,
sel TYPE char1,
matnr TYPE matnr,
bldat type char10,
END OF t_data.
DATA: it_tab TYPE STANDARD TABLE OF t_data,
it_fcat TYPE slis_t_fieldcat_alv.
DATA: wa_tab TYPE t_data,
wa_fcat TYPE slis_fieldcat_alv,
wa_layout type SLIS_LAYOUT_ALV.
data: lv_repid TYPE syrepid.
data : lv_date type NLEI-IBGDT,
lv_outdate type RN1DATUM-DATEX,
lv_format type RN1DATUM-FORMAT value 'YYYY-MM-DD'.
lv_repid = sy-repid.
lv_date = sy-datum.
CALL FUNCTION 'FORMAT_DATE_4_OUTPUT'
EXPORTING
datin = lv_date
format = lv_format
IMPORTING
DATEX = lv_outdate.
move lv_outdate to wa_tab-bldat.
wa_tab-matnr = '0000001'.
APPEND wa_tab TO it_tab.
lv_date = sy-datum + 1.
CALL FUNCTION 'FORMAT_DATE_4_OUTPUT'
EXPORTING
datin = lv_date
format = lv_format
IMPORTING
DATEX = lv_outdate.
move lv_outdate to wa_tab-bldat.
wa_tab-matnr = '0000002'.
APPEND wa_tab TO it_tab.
lv_date = sy-datum + 2.
CALL FUNCTION 'FORMAT_DATE_4_OUTPUT'
EXPORTING
datin = lv_date
format = lv_format
IMPORTING
DATEX = lv_outdate.
move lv_outdate to wa_tab-bldat.
wa_tab-matnr = '0000003'.
APPEND wa_tab TO it_tab.
wa_fcat-fieldname = 'SEL'.
wa_fcat-ref_fieldname = 'XCHPF'.
wa_fcat-ref_tabname = 'MARA'.
wa_fcat-edit = 'X'.
wa_fcat-checkbox = 'X'.
APPEND wa_fcat TO it_fcat.
CLEAR : wa_fcat.
wa_fcat-fieldname = 'MATNR'.
wa_fcat-ref_fieldname = 'MATNR'.
wa_fcat-ref_tabname = 'MARA'.
APPEND wa_fcat TO it_fcat.
CLEAR : wa_fcat.
wa_fcat-fieldname = 'BLDAT'.
wa_fcat-ref_fieldname = 'BLDAT'.
wa_fcat-ref_tabname = 'BKPF'.
APPEND wa_fcat TO it_fcat.
call 'REUSE_ALV_GRID_DISPLAY'' after this
Edited by: Ankur Parab on Oct 1, 2009 2:50 PM
Edited by: Ankur Parab on Oct 1, 2009 2:51 PM -
Formatted Search for Delivery Date field in SO not working
Hi All
Can anyone help me as to why my formatted search is not working?
I am currently using SAP B1A SP01 Patch 19.
I have created a user query as follows:
SELECT $ [$10.0.DATE] + 5
When I add this to the delivery field within the Sales Order and bring through the saved query which I set to auto refresh when the Posting Date field changes and to Display Saved Values it doesn't work.
Any ideas?
Thanks and best wishes
GailHI Gail,
If I am not mistaken you want to add days to the posting date...if that is so then try this out:
SELECT $[ORDR.DocDate.DATE]+5 From ORDR T0 For Browse
Set The indicator to Auto Refresh when the fields change
Nagesh
Maybe you are looking for
-
To get import value of table spoolids in CALL function 'smartfomr' ?
I am calling smartform as like under: DATA:l_doc_output_info TYPE ssfcrespd, tab_otf_data TYPE ssfcrescl, l_job_output_options TYPE ssfcresop. CALL FUNCTION FNAME IMPORTING DOCUMENT_OUTPUT_INFO
-
Just last week, I plugged in my iphone 3g into iTunes and for some reason I can't edit my apps anymore. All the other tabs (music, video, etc.) are all fine, but my apps tab/screen is all grayed out. I can't edit any of my apps now. What's the dea
-
Solution manager can not open pdf documents
What is the reason Solution manager (we have still 3.2) can not open pdf documents (under project documentation). Thank you in advance
-
Hi, I have to debug a smartform which is in production system. So, that I con't declare a static break point by 'Break username'. So,Could anyone explain about the possible ways of debugging of a smartform and various advantages of invidividual w
-
Attribute does nit exist after the upgrade
Hi, We have upgrdaed from BBPCRM 4 to SRM5.0. After the upgrdade we faced the following issue. While executing the transaction COMMPR01, we receive an error message "Attribue XXX does not exist". This attribute was maintained before the upgrade and a