how can get the date in this format “31-jun-2013”

Posted by Kumartyr under C# on 8/14/2013 | Points: 10 | Views : 1774 | Status : [Member] | Replies : 4
how can i get the date in this format "31-jun-2013"

at runtime if user type in the above format in the textbox ..it will fetch the matching rows of data for the specified date and filter that and show in datagridview

so for that i want to compare the date format with the text typed in textbox

string todaydate = Convert.ToString(DateTime.Today);

DateTime DTM = Convert.ToDateTime(todaydate);

string datetoday = DTM.ToString("dd-MMM-yyyy");

if (TypeHereTextBox.Text == datetoday)

{
OLCMND2 = new OracleCommand("Select * from TABLENAME where DATE = '" + TypeHereTextBox.Text + "'", CON);

OADAP1 = new OracleDataAdapter(OLCMND2);
OADAP1.Fill(DTBLE2);

DatagridView.DataSource = DTBLE2;
}

how can it be solved




Responses

Posted by: Bandi on: 8/14/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
May be try this?
OracleCommand("Select * from TABLENAME where DATE = 'to_date(" + TypeHereTextBox.Text + "', 'DD-Mon-YYYY')", CON); 

If not working, let us know the format of date values in the [b]DATE[/b] column
Refer this link once...
http://bytes.com/topic/oracle/answers/65794-oracle-sql-query-date

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Kumartyr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 8/14/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
DateTime DTM = Convert.ToDateTime(todaydate); 

string datetoday = DTM.ToString("dd-MMM-yyyy");
if (TypeHereTextBox.Text == datetoday)
{
OLCMND2 = new OracleCommand("Select * from TABLENAME where to_date(DATE, 'DD-Mon-YYYY') = to_date('" + TypeHereTextBox.Text + "', 'DD-Mon-YYYY')", CON);
OADAP1 = new OracleDataAdapter(OLCMND2);
OADAP1.Fill(DTBLE2);
DatagridView.DataSource = DTBLE2;
}

In your code you have compared DATE type data with string value...
try the following SELECT statement
    OLCMND2 = new OracleCommand("Select * from TABLENAME where to_date(DATE, 'DD-Mon-YYYY') = to_date('" + TypeHereTextBox.Text + "', 'DD-Mon-YYYY')", CON); 

refer this link for date formats in oracle
http://ss64.com/ora/syntax-to_date.html

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Kumartyr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kumartyr on: 8/16/2013 [Member] Starter | Points: 25

Up
0
Down
hi i got the solution guys

string[] arrayData = TextBox.Text.Split('-');

if (arrayData.Length == 3)

OLCMND2 = new OracleCommand("Select VISITORCOUNT,REMARKS,to_date(to_char(TODAYDATE, 'DD-MON-YYYY'),'DD-MON-YYYY') AS TODAYDATE,CARDNUMBER,PHOTO from VMS_VISITOR where TODAYDATE = TO_DATE('" + TypeHereTextBox.Text + "','dd-MON-yyyy')", CON);

OADAP1 = new OracleDataAdapter(OLCMND2);
OADAP1.Fill(DTBLE2);

DatagridView.DataSource = DTBLE2;

Thanks for all your responses guys



Kumartyr, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 8/16/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
We too provided the same thing...
OracleCommand("SELECT .................................. where TODAYDATE = TO_DATE('" + TypeHereTextBox.Text + "','dd-MON-yyyy')", CON);

Why are you checking this condition?
string[] arrayData = TextBox.Text.Split('-'); 

if (arrayData.Length == 3)

What will happen if user enters different format for DATE in TextBox?

The below code snippet also do the same thing as above
DateTime DTM = Convert.ToDateTime(todaydate); 

string datetoday = DTM.ToString("dd-MMM-yyyy");
if (TypeHereTextBox.Text == datetoday)



Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Kumartyr, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response