typecast string to datetime

I wrote the below program to get date value based on the input parameter
The output for this code is currentDate which is a string object.
I am sending this output into a datetime field,
as i am returning string it cant fit into that field and showing me null

so is it possible to typecast this output CurrentDate into datetime format.

plz: Ignore few methods like IAdaptorParameter the whole point here is to convert string
to a format acceptable by datetime textbox.

Experiment :
CurrentDate = dateformat.format(rs2.getTime("systime"));

instead of above stmt I used

CurrentDate =rs2.getTime("systime");

so now it is date object and when i send this to datetime text field.

It showed output 8/4/2011 3:34:55 in date box nothing in seconds box
along with an error complaining not in data is not in the format
of mmm d,yyyy h:mm:ss a

so i used simple date format to do it...
import java.text.SimpleDateFormat;
import java.util.Date;

import com.documentum.fc.client.DfClient;
import com.documentum.fc.client.DfQuery;
import com.documentum.fc.client.IDfClient;
import com.documentum.fc.client.IDfCollection;
import com.documentum.fc.client.IDfQuery;
import com.documentum.fc.client.IDfSession;
import com.documentum.fc.client.IDfSessionManager;
import com.documentum.fc.common.DfException;
import com.documentum.fc.common.DfLoginInfo;
import com.documentum.fc.common.IDfLoginInfo;
import com.documentum.tools.adaptor.AdaptorException;
import com.documentum.tools.adaptor.IAdaptorParameter;
import com.documentum.tools.adaptor.configuration.IAdaptorConfiguration;

public class DohCreateDateAdaptor implements IDohCustNameAdaptor{
	IDfCollection rs = null;
	String password = "passsword";
	String username = "username";
	String repositoryName = "docbase";
	IDfSession session = null;
	IDfSessionManager sMgr = null;
	IAdaptorParameter parameter = null;
	public Object execute(IAdaptorParameter[] parameters) throws AdaptorException {
		// TODO Auto-generated method stub
		Object CurrentDate = null;
		Object request_object_id = null;
		String pattern = "mmm d,yyyy h:mm:ss a";
		SimpleDateFormat dateformat = new SimpleDateFormat(pattern);
		if(parameters.length == 1)
			IAdaptorParameter parameter = parameters[0];
			request_object_id = parameter.getObject();
		try {
			new DfClient();
			IDfClient client = DfClient.getLocalClient();
			sMgr = client.newSessionManager();
			IDfLoginInfo logininfo = new DfLoginInfo();
			sMgr.setIdentity(repositoryName, logininfo);
			session = sMgr.getSession(repositoryName);	
			IDfQuery query = new DfQuery();
			IDfQuery query1 = new DfQuery();
			//IDfQuery query2 = new DfQuery();	
				query.setDQL("SELECT DATE(now) as systime from dm_server_config"); 
				rs2 = query.execute(session, DfQuery.DF_READ_QUERY);
				while(rs2.next()) {
					CurrentDate = dateformat.format(rs2.getTime("systime"));
				query1.setDQL("select r_creation_date from dm_document where r_object_id = "+"'"+request_object_id+"'");
				rs1 = query1.execute(session, DfQuery.DF_READ_QUERY); 
				while(rs1.next()) {
					CurrentDate =  dateformat.format(rs1.getTime("r_creation_date"));
		catch(DfException e){
		catch(Exception e) {
		finally {
		return CurrentDate;
	public void destroy() throws AdaptorException {
		// TODO Auto-generated method stub
	public void init(IAdaptorConfiguration arg0) throws AdaptorException {
		// TODO Auto-generated method stub

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Your pattern does not match the actual format of your date srring.
It should be:

SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
(Check upper and lower case for mm, MM
In SimpleDataFormat API - I don't have access right now, but the general format is as I wrote)
If your time is I AM/PM then it should be
"MM/dd/yyyy hh:mm:ss a"
But there should not be any comma, as you specified
Yes, now I checked,actually it was correct

String s = "8/4/2011 3:55:00 am";
SimpleDateFormat f = new SimpleDtaerForma("MM/dd/yyyy hh:mm:ss a);
Date d;
String sDate = f.format(d);

This has  examples of patterns:

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Sathish David Kumar NArchitectCommented:
>>CurrentDate = dateformat.format(rs2.getTime("systime"));

should be

CurrentDate = dateformat.format(rs2.getTimestamp("systime"));

Open in new window

Mick BarryJava DeveloperCommented:
>             String pattern = "mmm d,yyyy h:mm:ss a";

As for_yan points out above, your format is wrong
for a start your using mmm for the month (M is month)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.