Change date format in SQL server using Java code - java

I have a column "created_date" in my table in SQL server. It is currently in format "dd-mm-yy hh:mm:ss" and I want to change it to "yyyy:MM:dd hh:mm:ss" using Java code.
Simple date format is throwing error. Is there any other way to do it?

Related

how to get the date in the format that is displayed in sql table?

I have an oracle database table with a date column. when I query the table date is displayed in dd-MMM-yy format. For example 17-OCT-19 format. But when I query the table from java and print the value I am seeing the date in yyyy-MM-dd format. Is there a way where I can fetch the date the same as that is displayed in dd-MMM-yy format? I have no idea why the date is getting displayed in a different format in java.
DateFormat activityDateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date activityDate = activityDateFormat.parse();
activityDateFormat = new SimpleDateFormat("dd-MMM-yy");
finalActivityDate = activityDateFormat.format(activityDate);
I am using the piece of code to convert the date from yyyy-MM-dd to dd-MMM-yy format. The NLS settings for Date format in the database are DD-MON-RR. Is there any reason why I don't get the date the same as DD-MON-RR? can someone please help me?
Select the date column as string and format it dd-mmm-yy from the SQL query.
The client you are using to query Oracle, SQL Developer is often used, is the one formatting the date.
Java gets the date as a date data type and will use whatever is the default format when converting it to a string

Jersey JSON Date formatting POJO Mapping

I have date stored in mysql db as DATETIME and the value is stored in db as
"2016-09-09 15:56:26"
I wanted to display in same format, I am using Jersey 1.19 with POJOMapping and I used Date format in pojo, but the value shown in API is as:
"createdDt":1473454586000
What is the right approach to display correct date format in GET API, should I use String?

Date comparison in MongoDb and Java

I have to compare an EQUAL comparison between dates from UI and DB. Its working with below code
ExtJs Code :-
xtype: 'datefield'
,fieldLabel:'By Date'
,name: 'byDate'
,format: 'd-m-Y'
,flex:1
and Code in Java is :-
query.addCriteria(Criteria.where("bookingtime").regex(byDate, "i"));
The format d-m-Y gives me date in format 27-11-2016 or 15-10-2016. If the date in DB is as same as in date from UI ,like 27-11-2016 etc, this works like a charm.
But the problems arises when I select date in UI as 07-01-2016 which becomes 7-1-2016 in java. Since date in DB is in format 07-01-2016 and it fails the match and I get nothing.
Could you please help.

Talend timestamp - Getting a zero value instead of timestamp

I am converting string to date using a tConvertType component in Talend.The data(source is in String) is getting loaded when I do the date pattern yyyy-mm-dd but when I try with timestamp yyyy-MM-dd HH:mm:ss then I am getting an error. The data from the source has the timestamp but then I am getting an error.
For Eg : I have the source as 2015-09-03 14:14:90 , since data is in string so used tconverttype and then for destination the data type is date. But if I use timestamp then I am getting an error of Unparseable date and if I change to yyyy-mm-dd then the data is coming as 2015-09-03 00:00:00 which is wrong
try
convert(timestamp,expression)
i had the same problem in the past and convert fixed that
Using the type date and date format "yyyy-MM-dd' 'HH:mm:ss" it works fine
I recommand you to use date format by pressing Ctrl+space and choose from the list.

SQL Server Date time to Salesforce Date in Mule

I have a SQL Server Datetime field with value 1962-04-04 00:00:00.0. This needs to be pushed into Salesforce date field through Mule. I am handling this conversion in the data mapper.
I have tried many possibilities but nothing works. Any pointers would help.
The last one I tried was as below. I thought it should work.
output.PersonBirthdate1 = str2date(input.DATE_OF_BIRTH, "yyyy-MM-dd hh:mm:ss.ZZZ");
But it gives an error:
Caused by: [Error: java.text.ParseException: Unparseable date: "1962-04-04 00:00:00.0"]
Bases on the format of the date,it would be:
str2date(input.DATE_OF_BIRTH,"yyyy-MM-dd HH:mm:ss.S")

Categories