sydneyram
asked on
Oracle's Date field is shown as DateTime in .NET GridView- Only need the Date part not the Time
Experts,
URGENT!!!!!!!!!!!!!!!!!!!! !!!!!!!!!
I need your assistance in converting a Date field returned from an ORACLE database(PLZ dont give SQL SERVER Solutions :) ) into a .NET Date field which is displayed in a Grid View which shows only the Date part and not the Time
(For Eg: the Value in GridView is 6/11/1986 12:00:00 AM and I want it as just 6/11/1986)
I cannot create that column as a bound field as my DataSet returns variable columns everytime. So, there might or might not be a DateField in the DataSet too depending on the Query I run against the Database.
I TRIED USING TO_CHAR(datecolumn, 'MM/DD/YY) function which converts it to CHAR TYPE and upon ORDER BY, that that particular filed is ordered as a STRING and NOT AS A DATE type.
An early response would be really appreciated and helpful.
Thanx.
URGENT!!!!!!!!!!!!!!!!!!!!
I need your assistance in converting a Date field returned from an ORACLE database(PLZ dont give SQL SERVER Solutions :) ) into a .NET Date field which is displayed in a Grid View which shows only the Date part and not the Time
(For Eg: the Value in GridView is 6/11/1986 12:00:00 AM and I want it as just 6/11/1986)
I cannot create that column as a bound field as my DataSet returns variable columns everytime. So, there might or might not be a DateField in the DataSet too depending on the Query I run against the Database.
I TRIED USING TO_CHAR(datecolumn, 'MM/DD/YY) function which converts it to CHAR TYPE and upon ORDER BY, that that particular filed is ordered as a STRING and NOT AS A DATE type.
An early response would be really appreciated and helpful.
Thanx.
you should be able to set the format of your date column in the grid.
ASKER
sdstuber,
I can set the format of my date column in the grid if it is a BOUND FIELD. And in my case I CANNOT BIND to one particular column since my query might return 1 to N variable columns every time depending on what columns the user desires to view.
For example:
CASE 1: Select fname, lname from Emp;
CASE 2: Select dateofbirth, fname, lname from Emp;
CASE 3: Select dateofbirth, admitdate from Emp;
CASE 4: Select admitdate, fname, dateofbirth, lname from Emp;
IN CASE 1, there is no date field at all but in the others there are date fileds. So, I cannot say which column will be in what order in the resultant Dataset that I bind to the my Grid View(it is auto generated to be more precise).
Hope I made my case more clear now.
I can set the format of my date column in the grid if it is a BOUND FIELD. And in my case I CANNOT BIND to one particular column since my query might return 1 to N variable columns every time depending on what columns the user desires to view.
For example:
CASE 1: Select fname, lname from Emp;
CASE 2: Select dateofbirth, fname, lname from Emp;
CASE 3: Select dateofbirth, admitdate from Emp;
CASE 4: Select admitdate, fname, dateofbirth, lname from Emp;
IN CASE 1, there is no date field at all but in the others there are date fileds. So, I cannot say which column will be in what order in the resultant Dataset that I bind to the my Grid View(it is auto generated to be more precise).
Hope I made my case more clear now.
1. you could convert Oracle date to string using 'YYYY/MM/DD' format, than ordaring should work properly
2. regardless your dynamic query having different sets of columns you somehow display them, I believe you could add code which can detect whither date field is returned and set format for it in the column definition.
For instance you could add processing of Bound event for your GridView and format value of Date column to string using thisDate.ToString("d")
2. regardless your dynamic query having different sets of columns you somehow display them, I believe you could add code which can detect whither date field is returned and set format for it in the column definition.
For instance you could add processing of Bound event for your GridView and format value of Date column to string using thisDate.ToString("d")
yes, even if you have a dynamic columns, you still have the ability (maybe some additional coding) to find the column that is a date and set that column's format
ASKER
OMC2000,
I thought of the same solution you specified in your Point #1. But the requirement states that the format of the date MUST be in MM/DD/YYYY which is the standard format. So, thats where my hands are cut off :(.
I would surely love to take the second approach you suggested, I thought of solutions like that but it in vain. Do you have a code snippet which could do that? I would be grateful if you really can send it over :).
Thanks.
I thought of the same solution you specified in your Point #1. But the requirement states that the format of the date MUST be in MM/DD/YYYY which is the standard format. So, thats where my hands are cut off :(.
I would surely love to take the second approach you suggested, I thought of solutions like that but it in vain. Do you have a code snippet which could do that? I would be grateful if you really can send it over :).
Thanks.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanx experts. I really appreciate your help.
There is no such thing as a "date only" type in Oracle.