Click here to Skip to main content
15,885,767 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I have this format date in source database as date type date.

"2016-07-10"


I need to convert it to below format

1943-11-05 00:00:00.000


What I have tried:

I have try below query for it

cast(column1 as timestamp)


But it gives me below result

"2016-07-10 00:00:00"


That is not perfect as per my requirement.
Posted
Updated 22-Apr-21 0:03am

1 solution

If your input value is 2016-07-10, why would you expect the output to be a completely different date?

Your actual output is exactly what you would expect given your input.

If you want to change the value to a different date, then you're going to have to explain how you calculate the output from the input.
 
Share this answer
 
Comments
Member 11776570 22-Apr-21 6:25am    
I have to convert it to datetime because data is convert from source system to destination system. So destination system has datetime data type in it.
Richard Deeming 22-Apr-21 6:27am    
And you have converted it to datetime. The only "problem" in your question is that the datetime uses the same date as the input, whereas your expected output uses a completely different date.

You need to re-read your question, and explain what the problem is.
Member 11776570 22-Apr-21 6:46am    
I just need to convert this 2016-07-10 date format to like this 1943-11-05 00:00:00.000 one noting else. In PostgresSQL
Richard Deeming 22-Apr-21 6:48am    
Which is exactly what you have done already!

The only "problem" you have is that you are expecting an input of 2016-07-10 to produce an output of 1943-11-05, but you haven't explained WHY you expect that, nor HOW you think the two values are related.
Member 11776570 22-Apr-21 7:07am    
Okay i got your point. Sorry my mistake.
It has date this 2016-07-10 need to convert it to 2016-07-10 00:00:00 in this format.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900