Date range converted to String format?
Simple question:
When I was an avid Crystal Reports 8.5 developer, I remember there was something that converted a Date Range to a string, which contained the character "[" for inclusive and "(" for exclusive and looked something like this:
"(2/24/08...3/15/09]"
What was that function again please?
HI,
Please try this link if this what you meant ? [Click Here |http://www.crystalreportsbook.com/Forum/forum_posts.asp?TID=1662&PN=1]
Try the DTStoDate function,
DateTime Strings
DTSToDate({DateTime String})
The DTSToDate({DateTime String}) function extracts the date from a
DateTime string field.
Hopes this is the one!
Regards,
Clint
Similar Messages
-
Date Difference between two dates which is in String format - Urgent
Hi,
My requirement is
String s1 = "04/24/2008" ; // in "mm/dd/yyyy" format
String s2 = "08/30/2010" ; // in "mm/dd/yyyy" format
Now i want to calculate the number of days between the two Strings(Dates).It's urgent.Please help me.A late entry:
If you want to turn a String into a Date, use SimpleDateFormat.
[Calculating Java dates: Take the time to learn how to create and use dates|http://www.javaworld.com/jw-12-2000/jw-1229-dates.html]
[Formatting a Date Using a Custom Format|http://www.javaalmanac.com/egs/java.text/FormatDate.html]
[Parsing a Date Using a Custom Format|http://www.javaalmanac.com/egs/java.text/ParseDate.html] -
Need to convert Date from calendar to String in the format dd-mom-yyyy
Need to convert Date from calendar to String in the format dd-mom-yyyy+..
This is absolutely necessary... any help plz..
Rgds
ArwinderLook up the SimpleDateFormat class: http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html
Arwinder wrote:
This is absolutely necessary... any help plz..For you maybe, not others. Please refrain from trying to urge others to answer your queries. They'll do it at their own pace ( if at all ).
People on the forum help others voluntarily, it's not their job.
Help them help you.
Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
(Yes I know it's on JavaRanch but I think it applies everywhere)
---------------------------------------------------------------- -
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); -
How to convert a String("yyyy-mm-dd") to the same but in Date format ?
Hi,
can anyone plz tell me how to convert a String to a date format.I'm using MSACCESS database.I want to store this string in the database.So i need to convert it to a date format since the table is designed such a way with date/time type for date field.I used SimpleDateFormat ,but i can't able to convert.The code is given below:
coding:
public String dateconvertion(String strDate)
try
SimpleDateFormat sdfSource = new SimpleDateFormat("yyyy-MM-dd");
Date date = sdfSource.parse(strDate);
SimpleDateFormat sdfDestination = new SimpleDateFormat("yyyy-MM-dd ");
strDate = sdfDestination.format(date);
catch(ParseException pe)
System.out.println("Parse Exception : " + pe);
return(strDate);
}i used prepared statement even now i am getting error like this.....
i have included the prepared statement package also...
my coding:
ResultSet rsdatetemp = null;
PreparedStatement ps = null;
String query ="select distinct itemcode from sales where bill date between ? and ?";
ps = precon.prepareStatement(query);
ps.setDate(1,d1);//d1 and d2 are in date format
ps.setDate(2,d2);
rsdatetemp = ps.executeQuery();
error :
symbol : method setDate(int,java.util.Date)
location: interface java.sql.PreparedStatement
ps.setDate(1,d1);
symbol : method setDate(int,java.util.Date)
location: interface java.sql.PreparedStatement
ps.setDate(2,d2); -
Converting a string into Date format
I am currently using a JSP.
I currently need to convert a string that holds a date in "dd/mm/yyyy" format to the jva.sql.Date format.
Any ideas as to what the proper way of doing this is?
Many thanks pplpublic java.sql.Date parseDate(String s) {
java.text.DateFormat dateFormatter= new java.text.SimpleDateFormat("dd/MM/yyyy");
return new java.sql.Date(dateFormatter.parse(s).getTime()); -
Convert a String Mar 7, 2008 to date in yyyy-dd-mm format
Hi,
Please help me to Convert a String Mar 7, 2008 to date in yyyy-dd-mm format..
have to store that Date in SQL Server date field in yyyy-dd-mm.
Regards,I done this and got the desired result 2008-03-07. Thanks... know checking it with my code :)
String ss = "Mar 7, 2008";
//System.out.println(ss);
try{
SimpleDateFormat dateFormat = new SimpleDateFormat("MMM dd, yyyy");
Date date = dateFormat.parse(ss);
System.out.println(date.toString());
System.out.println(new java.sql.Date(date.getTime()));
}catch(Exception ee)
ee.printStackTrace();
} //endsEdited by: bunty_india on May 8, 2008 8:09 PM -
How to convert an xml data(clob) in database to string format in bpel??
Now I am learning SOA ,I have one scenario which I store the each record in xml format in database from file adapter ,extract the xml data and store the data in another table ...Give me any suggestions which I slove these issue .
Thanks in advance.Hi
You can try the below xpath function to convert the xml into string - orcl:get-content-as-string(/xsdLocal:SAPOrderRequest)
To convert the string back to XML - ora:parseEscapedXML(bpws:getVariableData('stringpayloadVar'))
Regards
Albin I -
How to convert BLOB data into string format.
Hi,
I have problem while converting blob data into string format.
for example,
Select dbms_lob.substr(c.shape.Get_wkb(),4000,1) from geotable c
will get me the first 4000 byte of BLOB .
When i using SQL as i did above,the max length is 4000, but i can get 32K using plsql as below:
declare
my_var CLOB;
BEGIN
for x in (Select X from T)
loop
my_var:=dbms_lob.substr(x.X,32767,1)
end loop
return my_var;
I comfortably convert 32k BLOB field to string.
My problem is how to convert blob to varchar having size more than 32K.
Please help me to resolve this,
Thanx in advance for the support,
NileshNilesh,
. . . .The result of get_wkb() will not be human readable (all values are encoded into some binary format).
SELECT utl_raw.cast_to_varchar2(tbl.geometry.get_wkt()) from FeatureTable tbl;
-- resulting string:
☺AW(⌂özßHAA
Å\(÷. . . .You may also want to have a look at { dbms_lob | http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_lob.htm#i1015792 } "The DBMS_LOB package provides subprograms to operate on BLOBs, CLOBs, NCLOBs, BFILEs, and temporary LOBs."
Regards,
Noel -
Convert a String to java.sql.Date Format
Hi,
I am having a String of containing date in the format 'dd/mm/yyyy' OR 'dd-MMM-YYYY' OR 'mm-dd-yyyy' format. I need to convert the string to java.sql.Date object so that I can perform a query the database for the date field. Can any one suggest me with the code please.
Regards,
Smithaimport java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.Date;
public class TestDateFormat
public static void main(String args[])
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
System.out.println(sdf.isLenient());
try
Date d1 = sdf.parse("07-11-2001");
System.out.println(d1);
Date d2 = sdf.parse("07:11:2001");
System.out.println(d2);
catch(ParseException e)
System.out.println("Error format, " + e);
See class DateFormat and SimpleDateFormat for detail. -
Converting string to date in mm/dd/yyyy format
Hi,
I used simpledateformat to convert date to "MM/dd/yyyy" format.
Now when i want to insert into db, i want the value as date object instead of string [returned by format method of SimpleDateFormat]
what should i do?
Date dt = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
System.out.println("Formatted date is coming as "+sdf.format(dt));
Date dt1 = sdf.parse(sdf.format(dt);
System.out.println("parsed date is coming as " +dt1);
output :
1 SOP returns 11/07/2007 [current date]
2 SOP returns Wed Nov 07 00:00:00 GMT+05:30 2007If you are using PreparedStatements setDate method, you need a java.sql.Date object, not a Java.util.Date object. You can create an sql.Date object from a util.Date object as follows:
java.sql.Date sqlDate = new java.sql.Date(dt.getTime());And, if you are not using PreparedStatement and its setDate method, then change now.
Doing
Date dt1 = sdf.parse(sdf.format(dt));is meaningless. You format the date to string, then parse the string back to a date? Why? Why not just use the original Date object? And you won't get a sql.Date object that way, either, as the DateFormat classes return a util.Date object.
Edit: And for more info:
A Date does not have a format. It is simply a number. The "format" only comes into play when printing the String representation of the Date, and that is not handled by the Date object itself (except when calling toString either explicitly or implicitly). -
How to convert a string into orcle date format
i need some information about converting string into date format.i have string like '20-SEP-05' .so we have to convert into date formate like yy-mm-dd' (2005-09-20).how can we do it.
Here's some code to help. I can't remember what method uses what format though
public static java.sql.Date sqlDateValueOf( String dateString ) {
String stringDate = null;
if ( dateString == null || dateString.length() < 10 ) return null;
String strDay = "";
String strMonth = "";
String strYear = "";
if ( dateString.substring(4,5).equals( "-" ) ) {
strDay = dateString.substring(8, 10);
if ( strDay.length() < 2 ) strDay = "0" + strDay;
strMonth = dateString.substring(5, 7);
strMonth = dateString.valueOf(Integer.parseInt(strMonth) - 1);
if ( strMonth.length() < 2 ) strMonth = "0" + strMonth;
strYear = dateString.substring(0, 4);
stringDate = strDay + "-" + strMonth + "-" + strYear;
else if ( dateString.substring(2,3).equals( "-" ) ) {
strDay = dateString.substring(0, 2);
if ( strDay.length() < 2 ) strDay = "0" + strDay;
strMonth = dateString.substring(3, 5);
strMonth = String.valueOf(Integer.parseInt(strMonth) - 1);
if ( strMonth.length() < 2 ) strMonth = "0" + strMonth;
strYear = dateString.substring(6, 10);
stringDate = strDay + "-" + strMonth + "-" + strYear;
Calendar cal = Calendar.getInstance();
cal.set( Calendar.YEAR, Integer.parseInt( strYear ) );
cal.set( Calendar.MONTH, Integer.parseInt( strMonth ) );
cal.set( Calendar.DAY_OF_MONTH, Integer.parseInt( strDay ) );
java.sql.Date outDate = new java.sql.Date( cal.getTimeInMillis() );
return outDate;
public static String toDateString( java.util.Date date) {
if ( date == null || date.toString().length() < 10 ) return null;
String outDate = "";
SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
outDate = df.format( date );
return outDate;
public static String toDateString( java.sql.Date date) {
if ( date == null || date.toString().length() < 10 ) return null;
String outDate = "";
SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
outDate = df.format( date );
return outDate;
public static String toDateString( java.sql.Date date, String format) {
if ( date == null || date.toString().length() < 10 ) return null;
String outDate = "";
SimpleDateFormat df = new SimpleDateFormat( format );
outDate = df.format( date );
return outDate;
public static String toDateString( java.sql.Timestamp date) {
if ( date == null || date.toString().length() < 10 ) return null;
String outDate = "";
SimpleDateFormat df = new SimpleDateFormat("dd-MM-yyyy");
outDate = df.format( date );
return outDate;
} -
Date Formatting, Converting from String to Timestamp
I am trying to convert a string date to timestamp.
I have tried a couple of different ways to arrive at the end result.
I am basically trying to convert a date in the "dd-MM-yyyy" format to a timestamp.
If I use the following code, I get a date like this "18-May-2004 12:00:00 AM".
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy);
Date dContractDate = sdf.parse("18-05-2004");
long dateInMilli = dContractDate.getTime();
bHelp.bcontractdate = new Timestamp(dateInMilli);
How can I make this code display the current time not midnight or some defaulted value?
Thanks.I think a clever person would reuse their Date.classObject and call Date.setTime() as opposed to always
rolling out a new Date()
Not really a question of cleverness. Your code wins
nothing. Objects are not magically created and garbage collected in the ether.
The cost of creating a Date is nothing
compared to the cost of a format() call. True, but not valid a valid statement pertaining to the issue which is
"does always rolling dates suffer a performance hit?"
Plus you lost clarity Maybe you loose track of your code if you don't make new Objects all the time,
but I have never suffered from this.
Why do you think Sun provided the setDate() method?
and thread-safety.I have only had Thread issues when I didn't program them properly.
Luckilly I always program the correctly ;) (Touch wood)
The facts as I seem are thus:
Rolling new dates on a 1.83 GHZ PC incurrs on average
a 19% penalty. Here is the proof.
Save this program and save it as DateTest.java
If you don't want to waste the time here are the results of running it
through the default 10 iterations.
Running 10 iterations.
Reuse of dates is 27% more efficient
Reuse of dates is 17% more efficient
Reuse of dates is 18% more efficient
Reuse of dates is 20% more efficient
Reuse of dates is 20% more efficient
Reuse of dates is 17% more efficient
Reuse of dates is 17% more efficient
Reuse of dates is 20% more efficient
Reuse of dates is 20% more efficient
Reuse of dates is 18% more efficient
Gaining "nothing " actually = 19% on average
Low percent diff = 17 High percent diff = 27
Run it 100 times and it should still be around 19%
With the hi time being about 47% (Probably the result of garbage collecting)
//////////////////////////////////// <PROOF> ///////////////////////////////////////
import java.util.Date;
public class DateTest
DateTest()
public int run()
int percent = 0;
int loopCount = 0;
Date date = null;
int z=0;
long start1=0,end1=0,start2=0,end2=0,now=0;
int time1 = 0,time2 = 0;
now = System.currentTimeMillis();
date = new Date(now);
loopCount = 10000000;
start1 = System.currentTimeMillis();
for(z=0;z<loopCount;z++)
now = System.currentTimeMillis();
date.setTime(now);
end1 = System.currentTimeMillis();
start2 = System.currentTimeMillis();
for(z=0;z<loopCount;z++)
now = System.currentTimeMillis();
date = new Date(now); // use 'now' so test loops are =.
end2 = System.currentTimeMillis();
time1 = (int)(end1 - start1);
time2 = (int)(end2 - start2);
percent = ((time2-time1)*100/time2);
System.out.println("Reuse of dates is "+percent+"% more efficient");
return percent;
public static void main(String args[])
int z=0;
int lowP=100,hiP = 0; // lowpercent/highpercent
DateTest d = new DateTest();
int loopCount = 0;
long totals = 0;
int average = 0;
int values[];
int retVal = 0;
try // Yea olde Lazy person's command line handler :)
loopCount = Integer.parseInt(args[0]);
catch(Exception any)
loopCount = 10;
if(loopCount == 0)
loopCount = 10;
values = new int[loopCount];
System.out.println("Running "+loopCount+" iterations.");
for(z=0;z<loopCount;z++) //
retVal = d.run();
if(lowP > retVal)
lowP = retVal;
if(hiP < retVal)
hiP = retVal;
values[z] = retVal;
for(z=0;z<loopCount;z++)
totals += (long)values[z];
average = (int)(totals/loopCount);
System.out.println(" Gaining \"nothing \" actually = "+average+"% on average");
System.out.println("Low percent diff = "+lowP+" High percent diff = "+hiP);
}////////////////////////////////// </PROOF> /////////////////////////////////////////
Your "nothing" is in fact on average about a 19% performance hit. per call.
These inefficiencies build up and java is infested with the,
Was it not so the java would run much more efficiently than it now does.
Ask yourself; why did Sun supply the setDate() method???
(T) -
Convert XML string into an abap format date and time
Hi,
Does anyone know of a method or a function module in ABAP which converts XML string into an abap format date and time.
Here is a part of the xml that I want to convert.
<ns2:EventDateTime>2009-07-02T10:13:45+10:00</ns2:EventDateTime>
<ns2:EventMessageTransmissionDateTime>2009-07-02T10:13:45.987+10:00</ns2:EventMessageTransmissionDateTime>
Currently EventDateTime and EventMessageTransmissionDateTime are type XSDDATETIME_Z and these are converted to proper dates and times. We will be changing these fields to a STRING instead of XSDDATETIME_Z. The reason for this is to make the field more versatile. The customer would be receiving dates with Zulu (2009-09-23T12:00:00Z), with offsets (2009-09-23T12:00:00+10:00/-10:00) and just local timestamp (2009-09-23T12:00:00). With this, we need to make the date fields as string
to be able to accept the various date formats (esp. the local timestamp).
I am looking for a standard function module or method that will convert the xml string to a proper date and time abap format.
Would appreciate anyone's help!
Thanks.
Edited by: eunice ocson on Jul 13, 2009 1:49 AM
Edited by: eunice ocson on Jul 13, 2009 1:50 AM
Edited by: eunice ocson on Jul 13, 2009 1:51 AM
Edited by: eunice ocson on Jul 13, 2009 1:51 AMHi Eunice
Use the FM 'SMUM_XML_PARSE'
for more info
[Convert XML string to ABAP|XML String to ABAP or GUI]
hope it helps you.
Thanks!! -
How can i convert if the date in string format
String lFstr = (String) pReq.getParameter("FND");
String lTstr = (String) pReq.getParameter("TND");
String lLstr = (String) pReq.getParameter("LWD");
System.out.println(lFstr + " " + lTstr + " " + lLstr);
//DateFormat ds = DateFormat.getDateInstance();
DateFormat dateFormatter = new SimpleDateFormat("dd/MM/yyyy");
Date lFdate = null;
Date lTdate = null;
Date lLdate = null;
try {
lFdate = dateFormatter.parse(lFstr);
lTdate = dateFormatter.parse(lTstr);
lLdate = dateFormatter.parse(lLstr);
} catch (Exception e) {
System.out.println(lFdate+" "+lTdate+" "+lLdate);
i am getting the values from request parameters at that time it is giving values.
after convertion of string to date it is giving the null value what is wrong in this codeIt might have thrown an exception. Try printing the stack trace in the catch block.
Maybe you are looking for
-
Multiple libraries on one Mac recognised by iPods?
I would like to have all my music in one location but have multiple libraries for different members of my family. When I plug in an iPod, say my daughter's, I want it to know whose iPod it is, and open the relevant library (my daughter's) so that I c
-
Hi, Is there a badi to split the PO in EBP based on a cutom field in the shopping cart? Thanks, Kumar
-
How to reduce the size of winsxs in windows 7 ultimate x64
Ok so first off there are some caveats to responding to this question 1.) Im on windows 7, so DONT refer to some "winsxs is important" vista link... 2.) i am well aware of what windows side by side is for, and appreciate dll ____ must be bad for some
-
Difference between Unique key and Primary key(other than normal difference)
Hello, 1).Can any one tell me any other difference between Unique key and Primary key other than it having NULLs. 2). What is the difference the words 'DISTINCT' and 'UNIQUE' in a sql query. Thanks in advance.
-
How can I make a survey automatically identify the user in the results?
How can I make a survey automatically identify the user in the results (so that it won't be anonymous)?