Date format conversion
Moderators: chulett, rschirm, roy
-
- Premium Member
- Posts: 38
- Joined: Fri Apr 22, 2005 6:07 am
Date format conversion
Hi,
I am using sequential file as source with char datatype and dataset as target file. I want to convert date format from dd/mm/yyyy to mm/dd/yyyy. I have tried using DateToString(StringToDate(Trim(myDate), "dd/mm/yyyy"), "mm/dd/yyyy") function but conversion is not proper. My understanding is that, for inner function it needs date format of input date and for outer function we have to give required date format. The output is '******'.
Then I have just tried with inside function by changing Project level and job level default date format to mm/dd/yyyy but output coming is yyyy-mm-dd. Please give me solution for this.
Thanks in advance.
-Amit
I am using sequential file as source with char datatype and dataset as target file. I want to convert date format from dd/mm/yyyy to mm/dd/yyyy. I have tried using DateToString(StringToDate(Trim(myDate), "dd/mm/yyyy"), "mm/dd/yyyy") function but conversion is not proper. My understanding is that, for inner function it needs date format of input date and for outer function we have to give required date format. The output is '******'.
Then I have just tried with inside function by changing Project level and job level default date format to mm/dd/yyyy but output coming is yyyy-mm-dd. Please give me solution for this.
Thanks in advance.
-Amit
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
You've missed the "%" signs on the date format descriptors. Try
And, of course, for this to work your input column (myDate) must be a string.
Code: Select all
DateToString(StringToDate(Trim(myDate), "%dd/%mm/%yyyy"), "%mm/%dd/%yyyy")
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
-
- Premium Member
- Posts: 38
- Joined: Fri Apr 22, 2005 6:07 am
Hi Ray,
Thanks for your reply. I am sorry, it was typo while posting this question, I have used correct format only. But still I am getting '****' in the target. I am getting correct result if target datatype is varchar(10), but when I make it to date this problem occurs. Is it because I am trying to save string in date column? If it is the case what is the solution to get correct date format? Even I have tried to use Left function and concatenate it and store it but result is ok when I am storing it in varchar(10) and problem occurs with date type.
Please help.
-Amit
Thanks for your reply. I am sorry, it was typo while posting this question, I have used correct format only. But still I am getting '****' in the target. I am getting correct result if target datatype is varchar(10), but when I make it to date this problem occurs. Is it because I am trying to save string in date column? If it is the case what is the solution to get correct date format? Even I have tried to use Left function and concatenate it and store it but result is ok when I am storing it in varchar(10) and problem occurs with date type.
Please help.
-Amit
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
-
- Premium Member
- Posts: 38
- Joined: Fri Apr 22, 2005 6:07 am
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
Trim(myDate) is illegal when myDate has data type Date. Similarly, StringToDate() expects a string argument, not a date argument.
That's why I asked about data type.
The next recommendation was going to be to change the data type to string (VarChar or Char) to see if that worked. Obviously it does.
That's why I asked about data type.
The next recommendation was going to be to change the data type to string (VarChar or Char) to see if that worked. Obviously it does.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
-
- Premium Member
- Posts: 38
- Joined: Fri Apr 22, 2005 6:07 am
-
- Participant
- Posts: 232
- Joined: Sat May 07, 2005 2:49 pm
- Location: USA
Hi Amit,
You can use the following logic
where Arg1 is the date in dd/mm/yyyy format
I always use this logic in my routine to convert date to US format (mm/dd/yyyy) and It works like a charm.
Thanks,
Naveen
You can use the following logic
Code: Select all
Ans = Arg1[4,2]:"/":Arg1[1,2]:"/":Arg1[7,4]
I always use this logic in my routine to convert date to US format (mm/dd/yyyy) and It works like a charm.
Thanks,
Naveen