Convert Date format while retaining datatype - Oracle

<>

This question already has an answer here:

Answers


Dates don't have formats, so you can't set the format when it is saved. Formats only come into play when converting to or from a string.

If you want to save just the month year with day and time being 1 and midnight, trunc(date_value, 'month'). Fomat models for round and trunc date.


Convert it back to a date.

SELECT to_date(TO_CHAR(SYSDATE, 'YYYY-MM'),'YYYY-MM') FROM DUAL

Of course, to be a valid date there must be a day component. This will be set to 1.

Alternatively, why not just store the sysdate? Next time you look at that value you will only be interested in the year and month.


Need Your Help

Service Applications and Google Analytics API V3: Server-to-server OAuth2 authentication?

php google-api oauth-2.0 google-analytics-api jwt

I'm trying to make a server application to routinely pull Google Analytics data from my own GA account. Note, it is a personal, server-side application accessing my own data, i.e. there is no end-u...

Increase the number of comments in the "previously entered comments" list when committing using subclipse

eclipse svn subclipse

When I commit something using the Subclipse plugin in Eclipse, the dialog allows me to pick a previously entered comment and use its contents again for the current commit comment.