Author |
Message
|
nukalas2010 |
Posted: Wed Jan 07, 2015 5:43 am Post subject: Convert YYYY-MM-DD (Dateformat) to dd/MM/yyyy (Date Format) |
|
|
 Master
Joined: 04 Oct 2010 Posts: 220 Location: Somewhere in the World....
|
Dears,
I am trying to cast of date fro one format to another, but ended up without solution
Code: |
Source -- DateFormat - YYYY-MM-DD
Target -- DateFormat - dd/MM/yyyy |
Can anybody throw some light on this..
I can able to achieve if its from Date to Character in the same format. but not from Date to Date.
Thanks in Advance, |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Jan 07, 2015 5:49 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Dates don't have formats.
Dates can be formatted into strings, or strings can use formats to extract information to populate a Date.
Dates don't have formats. |
|
Back to top |
|
 |
nukalas2010 |
Posted: Wed Jan 07, 2015 6:00 am Post subject: |
|
|
 Master
Joined: 04 Oct 2010 Posts: 220 Location: Somewhere in the World....
|
mqjeff wrote: |
Dates don't have formats. |
Could you please elaborate on this.. Eg: dd-MM-YYYY, dd/mm/yyyy are not examples of date format. ???
Code: |
Dates can be formatted into strings, or strings can use formats to extract information to populate a Date.
|
Yes, we can format to strings or vice versa. But not date to date. |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Jan 07, 2015 6:04 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
The ESQL date, datetime, time, and etc. etc. etc have internal representations.
They hold the VALUE of the date, which has no format at all.
So it doesn't hold a value of "7/1/2015", it holds the VALUE that represents that date.
So it is meaningless to try and cast a Date object from one format to another, since dates have no format.
There's no more elaboration I can give on that. Dates have no format. |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Jan 07, 2015 6:07 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
On a more practical sense for your quandry:
- cast string to date using format
- cast date to string using format
- conversion complete
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
nukalas2010 |
Posted: Wed Jan 07, 2015 6:22 am Post subject: |
|
|
 Master
Joined: 04 Oct 2010 Posts: 220 Location: Somewhere in the World....
|
hmm its clear.. Thanks jeff  |
|
Back to top |
|
 |
Vitor |
Posted: Wed Jan 07, 2015 6:27 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
nukalas2010 wrote: |
Could you please elaborate on this.. Eg: dd-MM-YYYY, dd/mm/yyyy are not examples of date format. ??? |
No, they're formatted representations of dates. A date variable is typically expressed as an integer number of seconds or milliseconds from an arbitrary date. The fact that (for example) a DATE column in a database looks like one of the formats you show when viewed through an explorer type tool doesn't change how it's held internally. The fact that a DATE literal is expressed in ESQL as a formatted string for the convienience of the developer doesn't change this.
A noteable exception to this (and one which I think may be relevant for you) is an XML document where an xsd:date is a text item formatted as yyyy-mm-dd. So that is the representation of a date. If however you look at (for example) the Java representation of a parsed XML document with an xsd:date, you won't see that string, you'll see the Java implementation (which is an int) with an implausibly high number.
So you can't "format" a date. You can format a string representation of a date. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Jan 07, 2015 6:32 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Sorry Vitor. Java Calendar information (date, time etc...) is usually a long not an int...  _________________ MQ & Broker admin |
|
Back to top |
|
 |
Vitor |
Posted: Wed Jan 07, 2015 6:36 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
fjb_saper wrote: |
Sorry Vitor. Java Calendar information (date, time etc...) is usually a long not an int...  |
Ok, it's a long. Which is a 64 bit integer. It's still not represented in Java as a formatted string.....
...grumble grumble....
...wretched Java...... _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
|