Convert date in sql format
how to convert a date in string format to sql date format?
thanx in advance
Use java.text.SimpleDateFormat to parse the String into a java.util.Date.
Create a java.sql.Date from the java.util.Date.
Use a PreparedStatement and its setDate() method to set the date in the SQL. The JDBC driver will take care of putting that java.sql.Date object into the correct format for your DB.
Similar Messages
-
How to convert date to ccyymm format
Hi,
How to convert date to ccyymm format.
Thanksdadivela wrote:
Re: How to convert date from ccyymm format to mmddyyI didn't inderstand. Date doesn't have any format. If you have a string in CCYYMM format, you would have to extract the YYMM from the string.
SQL> SELECT SYSDATE,
2 TO_CHAR (SYSDATE, 'ccyymm') Date_Fm,
3 SUBSTR (TO_CHAR (SYSDATE, 'ccyymm'), 3) YYMM
4 FROM DUAL
5 /
SYSDATE DATE_F YYMM
08-JUN-09 210906 0906You can use this string to convert it to date. Note that since DD part of your date was not their in the resultan string, the converted date will fall back to first of the month specified.
SQL> SELECT SYSDATE,
2 TO_CHAR (SYSDATE, 'ccyymm') Date_Fm,
3 SUBSTR (TO_CHAR (SYSDATE, 'ccyymm'), 3) YYMM,
4 TO_DATE (SUBSTR (TO_CHAR (SYSDATE, 'ccyymm'), 3), 'YYMM') conv_Dat
e
5 FROM DUAL
6 /
SYSDATE DATE_F YYMM CONV_DATE
08-JUN-09 210906 0906 01-JUN-09
SQL>Then convert the date into the required format using TO_CHAR Function
SQL> SELECT SYSDATE,
2 TO_CHAR (SYSDATE, 'ccyymm') Date_Fm,
3 SUBSTR (TO_CHAR (SYSDATE, 'ccyymm'), 3) YYMM,
4 TO_DATE (SUBSTR (TO_CHAR (SYSDATE, 'ccyymm'), 3),
5 'YYMM') conv_Date,
6 TO_CHAR(TO_DATE(SUBSTR(TO_CHAR (SYSDATE, 'ccyymm'),3),
7 'YYMM'), 'MMDDYY') New_Format
8 FROM DUAL
9 /
SYSDATE DATE_F YYMM CONV_DATE NEW_FO
08-JUN-09 210906 0906 01-JUN-09 060109
SQL>Hope this helps.
Regarads,
Jo -
How to convert date from ccyymm format to mmddyy
hi,
How to convert date from ccyymm format to mmddyyPlease don't multipost. This question has been answered in your first post.
How to convert date to ccyymm format
Regards,
Jo -
Convert smalldatetime type SQL format to Date in OBIEE
I have a SQL database which holds date in the smalldatetime type SQL format. I want to read this date in the OBIEE. How I can achieve this. I didn't find any direct CAST for this OBIEE Answers.
thanks,
Nareshsorry to confuse here. I would reframe my question as following
Hi,
I have a data in SQL Database which is in ‘float’ format. The data is being stored for TimeStamp such that casting it for ‘smalldatetime’ gives the exact timestamp in SQL Server.
For example I have dates (dTime) column and the converted columns when did casting for smalldatetime gives following result (in SQL Server)
dTime (Float) ########################## small_date_time (CAST dTime AS smalldatetime)
40322.271099537 ########################## May 26 2010 6:30AM
40322.275706018503 ########################## May 26 2010 6:37AM
40415.121770833299 ########################## Aug 27 2010 2:55AM
Now problem is I have this (dTime) column coming as Double in OBIEE and when I’m trying to convert this to TIMESTAMP/DATE it gives error.
To Simplify I tried following query in Answers directly.
CAST(CAST('40322.271099537' AS CHAR) AS TIMESTAMP)
and the error shown is below
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 43113] Message returned from OBIS. [nQSError: 43119] Query Failed: [nQSError: 46046] Datetime value 40322.271099537 does not match the specified format. (HY000)
Do we have a way to get the format right by using cast or any other function.
Edited by: naresh kumar on Oct 20, 2010 2:25 AM
Edited by: naresh kumar on Oct 20, 2010 2:26 AM -
Converting Date Column to format MM/DD/YYYY in RPD
Hi all,
I have a requirement like converting a Date column to format MM/DD/YYYY in RPD. Any help as we are not supposed to use the BI Answers Data Fomat for showing this format.
Thankyou,
Edited by: [email protected] on May 10, 2010 11:49 PMHi Saichand,
I need the resulting column in DATE format only. The solution which you specified converts the datatype to character. Is there anyway to convert the format but not the datatype. -
How to convert date to system format
Is there any function module for converting the date in YYYYMMDD format to our own system format. eg. 21.07.2006
Hi Abinaya,
Use this func module <b>CONVERSION_EXIT_PDATE_OUTPUT</b>
Please award points if u find it useful
Regards,
Viven -
Convert date to internal format
Hi,
I am getting date in the format as detailed below:
10/16/2005, 6/16/2005, 10/6/2005 - MM/DD/YYYY
I have to convert it to the internal date format.
Please help with the code.
Thanks
SAPBWHi,
Use Function module <b>CONVERT_DATE_TO_INTERNAL</b>.
It will consider all types of date formats 10/16/2005, 6/16/2005, 10/6/2005 etc. Whether you will give 1 or 2 digits to month or date. You can also give 2 digits to year even then it will converts to internal format.
<b>You need to give dates in User defined format otherwise it generates an exception DATE_EXTERNAL_IS_INVALID.</b>
DATA V_EXT_DATE(10) VALUE '10/06/2005'.
DATA V_DATE TYPE SY-DATUM.
CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
EXPORTING
date_external = V_EXT_DATE
IMPORTING
DATE_INTERNAL = V_DATE
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.
ENDIF.
WRITE:/ 'INTERNAL FORMAT OF DATE IS: ', V_DATE.
Thanks,
Vinay
Thanks,
Vinay -
Routine to convert dats to dec format
Hi experts..
I have one cube having date in DEC format and flatfile having date in DATS(yyyymmdd) format. i have used a routine in transfer rules as follows..
DATA: dats1 type p.
dats1 = TRAN_STRUCTURE-calday.
RESULT = dats1.
but i m not getting the date in cube in DEC format...?
Plz correct me...sorry use TYPE /BIC/OIZDEC_DATE instead of LIKE...
one question, how is this filed stored in your cube fact table at the end?
Can you see the /BIC/F<cube> value in SE16 and let me know?
Can you also try to post your yyyymmdd directly without any routine? What's the result?
Perhaps the system converts it automatically into yyyymmdd anyway; this would mean that the behaviour is correct thus why do you want to post the numeric representation anyway??
Olivier.
Message was edited by:
Olivier Cora -
How to convert date in varchar format to TimeZone format?
Hi,
Iam having a date '14-05-08 09:46:35 AM' (in Varchar format). How to convert this date to TimeZone ('IYYY-MM-DD"T"HH12:MI:SS"Z"FX') format?
For Example,
My input date is '14-05-08 09:46:35 AM' and I need output as '2008-05-14T09:46:35Z'.
How to convert this?
Thanks in Advance.Hi,
You would look up the TO_TIMESTAMP and the TO_CHAR functions in the SQL reference manual for the version you don't mention, and make up the solution yourself, rather than asking someone else to do your homework.
Sybrand Bakker
Senior Oracle DBA -
Converting date in french format
Hi All,
Hi All,
Please let me know if you have any idea
I am converting the date to French /infact multi lang
select to_char(sysdate,'Fmddth Month, yyyy','NLS_DATE_LANGUAGE =FRENCH') from dual
so this is giving me "8th Septembre, 2011"
but what i want is "8er Septembre, 2011" instead of "th" i need "er"
Thanks & Regards,
Dhanafrom http://download.oracle.com/docs/cd/B19306_01/server.102/b14225/ch3globenv.htm
Example 3-12 NLS_DATE_LANGUAGE=FRENCH, Month and Day NamesAs an example of how to use NLS_DATE_LANGUAGE, set the date language to French:
ALTER SESSION SET NLS_DATE_LANGUAGE = FRENCH;
Enter a SELECT statement:
SELECT TO_CHAR(SYSDATE, 'Day:Dd Month yyyy') FROM DUAL;
You should see output similar to the following:
TO_CHAR(SYSDATE,'DAY:DDMONTHYYYY')
Vendredi:07 Décembre 2001
When numbers are spelled in words using the TO_CHAR function, the English spelling is always used. For example, enter the following SELECT statement:
SQL> SELECT TO_CHAR(TO_DATE('12-Oct.-2001'),'Day: ddspth Month') FROM DUAL;
You should see output similar to the following:
TO_CHAR(TO_DATE('12-OCT.-2001'),'DAY:DDSPTHMONTH')
Vendredi: twelfth Octobre -
Convert date format from MONTH-YEAR to dd/mm/yyyy
Dear All
i want to get parameter in form of MONTH-YEAR AND WANT TO CONVERT DATE INTO 'THIS FORMAT dd/mm/yyyy' IT GIVES ME ERROR PLEASE GUIDE.
SELECT
TO_CHAR (PTP.END_DATE,'MONTH-YY') ,
to_date ( TO_CHAR (PTP.END_DATE ,'DD-MONTH-YYYY') ,'dd/mm/yyyy'),
--- i want to gent parameter in from of MONTH-YEAR AND WANT TO CONVERT DATE INTO 'THIS FORMAT dd/mm/yyyy' IT GIVES ME ERROR PLEASE GUIDE
to_date ( TO_CHAR (PTP.END_DATE ,'MONTH-YYYY') ,'dd/mm/yyyy'),
ADD_MONTHS((to_date ( TO_CHAR (PTP.END_DATE ,'MONTH-YYYY') ,'dd/mm/yyyy'),-1)
--- i want to gent parameter in from of MONTH-YEAR AND WANT TO CONVERT DATE INTO 'THIS FORMAT dd/mm/yyyy' IT GIVES ME ERROR PLEASE GUIDE
ptp.END_DATE PERRIODS_NAME
from per_time_periods ptp
Regards
Edited by: user10941925 on Nov 28, 2011 12:23 AMHello just check
SQL> select hiredate from emp;
HIREDATE
17-DEC-80
20-FEB-81
22-FEB-81
02-APR-81
28-SEP-81
01-MAY-81
09-JUN-81
09-DEC-82
17-NOV-81
08-SEP-81
12-JAN-83
03-DEC-81
03-DEC-81
23-JAN-82
14 rows selected.
SQL> select to_char(hiredate,'month-year') from emp;
TO_CHAR(HIREDATE,'MONTH-YEAR')
december -nineteen eighty
february -nineteen eighty-one
february -nineteen eighty-one
april -nineteen eighty-one
september-nineteen eighty-one
may -nineteen eighty-one
june -nineteen eighty-one
december -nineteen eighty-two
november -nineteen eighty-one
september-nineteen eighty-one
january -nineteen eighty-three
december -nineteen eighty-one
december -nineteen eighty-one
january -nineteen eighty-two
14 rows selected.
SQL> select to_char(hiredate,'dd/mm/yyyy') from emp;
TO_CHAR(HI
17/12/1980
20/02/1981
22/02/1981
02/04/1981
28/09/1981
01/05/1981
09/06/1981
09/12/1982
17/11/1981
08/09/1981
12/01/1983
03/12/1981
03/12/1981
23/01/1982
14 rows selected.
SQL> -
Convert data from cobol to SAP-R/3
Hi Experts,
Plz let me to know, How to Convert data in cobol format to SAP-R3?
I get Cobal data in a file that should be updated to SAP..
Thanks & Regards,
SarathS.Hi.
It should be in excel sheet if you want transafer data from any Legacy to SAp,Not only cobol,so first convert data to excel then trasfer to SAP.
Regards.
jay -
How to convert date dd.mm.yyyy TO Month ddth YYYY?
hi friends,
how to convert date into this format.
ex:
date : 04.11.2008
has to convert as
October 04th, 2008
th has to be set SUPERSCRIPT.
Plz any helps....
Regards,
Shankar.check this..FM
CONVERT_DATE_TO_EXTERNAL
or we can do this using split or concatenate functions like below
*CALCULATING THE MONTH FOR THE BODY OF THE EMAIL MSG
IF GD_EBODY_BB = '01' .
GD_EBODY_BB = 'January' .
ELSEIF GD_EBODY_BB = '02' .
GD_EBODY_BB = 'February' .
ELSEIF GD_EBODY_BB = '03' .
GD_EBODY_BB = 'March' .
ELSEIF GD_EBODY_BB = '04' .
GD_EBODY_BB = 'April' .
ELSEIF GD_EBODY_BB = '05' .
GD_EBODY_BB = 'May' .
ELSEIF GD_EBODY_BB = '06' .
GD_EBODY_BB = 'June' .
ELSEIF GD_EBODY_BB = '07' .
GD_EBODY_BB = 'July' .
ELSEIF GD_EBODY_BB = '08' .
GD_EBODY_BB = 'August' .
ELSEIF GD_EBODY_BB = '09' .
GD_EBODY_BB = 'September' .
ELSEIF GD_EBODY_BB = '10' .
GD_EBODY_BB = 'October' .
ELSEIF GD_EBODY_BB = '11' .
GD_EBODY_BB = 'November' .
ELSEIF GD_EBODY_BB = '12' .
GD_EBODY_BB = 'December' .
ENDIF .
*ATTACHMENT SUBJECT LINE MODIFICATION
IF GD_EBODY_CC = '01'.
CONCATENATE GD_EBODY_CC 'st' INTO GD_EBODY_CC .
ELSEIF GD_EBODY_CC = '02' .
CONCATENATE GD_EBODY_CC 'nd' INTO GD_EBODY_CC .
ELSEIF GD_EBODY_CC = '03' .
CONCATENATE GD_EBODY_CC 'rd' INTO GD_EBODY_CC .
ELSEIF GD_EBODY_CC = '31'.
CONCATENATE GD_EBODY_CC 'st' INTO GD_EBODY_CC .
ELSEIF GD_EBODY_CC = '21'.
CONCATENATE GD_EBODY_CC 'st' INTO GD_EBODY_CC .
ELSE .
CONCATENATE GD_EBODY_CC 'th' INTO GD_EBODY_CC .
ENDIF .
regards
ansumesh
Edited by: Ansumesh Kumar Samal on Nov 4, 2008 9:02 AM -
Hi
I need to convert dates from user format to internal format.
Does some body knows wich FM can i use for convert text field '15.3.2010' to date field '20100315' ?
Regards
FrankModerator message - Please see How to post code in SCN, and some things NOT to do... before posting (date question) - post locked
Rob -
Convert a date in String format to a Date
Hi,
How can I convert a date in String format to a Date object?
I have tried:
import java.text.*;
import java.io.*;
import java.util.Date;
import java.util.Locale;
import java.sql.*;
public class casa {
public static Connection con = null;
public static Statement s = null;
public static String sql = null;
public static String mydate = "01.01.2001";
/** Creates a new instance of casa */
public casa() {
public static void main(String[] args) throws SQLException{
try {
DateFormat shortFormat = DateFormat.getDateInstance(DateFormat.SHORT);
Date date = shortFormat.parse(mydate);
//Open Database
con = getConnection();
s = con.createStatement();
sql = "select date1 from table1 where date1 <= '"+date+"'";
ResultSet rs = s.executeQuery(sql);
while(rs.next()){
String aba = rs.getString("datum");
System.out.println("New Datum = "+aba);
} catch (Exception ex ) {
ex.printStackTrace();
closeConnection(s, con);
//Connection
private static Connection getConnection() {
Connection con = null;
String user ="aouzi";
String passe ="aouzi";
String url = "jdbc:db2:EjbTest";
try {
//Datenbanktreiber laden
Class.forName("COM.ibm.db2.jdbc.app.DB2Driver");
//Verbindung herstellen
con = DriverManager.getConnection(url,user,passe);
}catch(ClassNotFoundException e){
} catch(SQLException e){}
return con;
//close Connection
private static void closeConnection(Statement s, Connection con) {
try {
s.close();
} catch (SQLException e) {}
try {
con.close();
} catch (SQLException e) {}
I'm getting the following errors:
COM.ibm.db2.jdbc.DB2Exception: [IBM][CLI Driver][DB2/NT] SQL0180N
The syntax of the representation of a date/time of day value as character sequence is false. .SQLSTATE=22007I'm pretty sure it won't understand what date.toString() returns. If you know what format the database understands, you do it like this:
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yy"); // e.g. 18-Apr-02
String datestring = sdf.parse(date);
and use that instead of date in your sql string. Some databases understands it if you do
"to_date('18-Apr-02')"
so you could include that in your sql string as well..
You could also try to make it a java.sql.Date and hope your jdbc driver knows how to convert it to a string that the database understands if you don't know the format:
con = getConnection();
PreparedStatement ps = con.prepareStatement("select date1 from table1 where date1 <= ?");
ps.setDate(new java.sql.Date(date.getTime()));
ResultSet rs = s.executeQuery(sql);
Maybe you are looking for
-
I am working with applets and have been getting the classdefnotfounderror exception and a wrong name error. After pouring over the archives and messing around, I have found a solution to my problem, but I don't know why it works. I think it has to do
-
Where can I find instructions on taking off all the plastic faceplates and bezels on a B&W G3 tower? I have removed everything but the large side panels... Any ideas out there? Thanks - this tower can REALLY use the cleaning...
-
Oracle 9 table names are not case sensitive
Sorry about the trivial question, but I noticed that when I am creating table in Oracle their names is always upper case. Example: CREATE TABLE MyTable (i NUMBER(5)) CREATE TABLE MYTable (i NUMBER(5)) CREATE TABLE MyTABLE (i NUMBER(5)) CREATE TABLE M
-
Portlet items in JDev w/OC4J standalone result in 500 (nullPointer) errors.
I am not sure if this belongs in the JDev or Portal discussion forums, so decided to start here. I loaded the Portal PDK extensions into JDev (1012) per instructions on OTN and was able to create an application with a default web template using the p
-
Hi I am practicing smartforms in 4.7. I have a tutorial based on 4.6c and they have complex section in the nodes. How do i translate this to 4.7 as there is no complex section available in this version. Detailed explanation would be helpful to me Poi