none
Wanted to make my application date format free from system date format. RRS feed

  • Question

  • I am fetching a date count from the database table .When querying on table directly it shows dd-mm-yy format but when i'm fetching it in my application it convert the date into system format which is mm-dd-yy.and i am getting an error of not a valid month .

    DataSet dsdate =oraExecuteQry("SELECT to_date(p_date, 'DD-MM-YY') FROM P_LOG");
    Ddt =Convert.ToDateTime(dsdate.Tables[0].Rows[1].ItemArray[0]).AddDays(1).ToShortDateString();
       

    int Count = Convert.ToInt16(oraExecuteQry("SELECT COUNT(*)  FROM HOLIDAY A  WHERE to_date(A.HOLIDAY_DATE, 'DD-MM-YY') =to_date('" + Ddt+ "', 'DD-MM-YY')").Tables[0].Rows[0].ItemArray[0]);

    above is the code i am using fetching date from one table increase it and then find its count in another table.In PC with system date format "DD-MM-YY" its working fine but in PC whose system date format is "MM-DD-YY" its giving error of not a valid month.

    Is there any way by which i can set format of my application by a global format which can be used throughout the application and make my application system date format free.


    SaiVaibhav@Acumen

    Tuesday, May 29, 2012 5:12 AM

Answers

  • Hi vaibhav vijay,

    no need to set any global format for this, these formats will be converted according to the culture you are using, if you not mention any culture to your application it will take system culture by default. So set the culture you want in web.config or where ever you need.

    Let me show you some example here please change it accordingly as per your requirement.

    CultureInfo culture = new CultureInfo(“en-US”);
    string today = DateTime.Now.ToString(“d”,culture);
    

    through out your application your date format will be same.

    Hope it will help you..


    Sai Kumar K (MCP)
    Blog: Sai's Stuff.
    WebSite: SantoshTechnologies.

    • Marked as answer by vaibhavsaral Tuesday, May 29, 2012 7:40 AM
    Tuesday, May 29, 2012 5:30 AM

All replies

  • Replace the second line of code above with the below piece of code.

    string dtValue = Convert.ToString(dsdate.Tables[0].Rows[1].ItemArray[0]);
    if(!String.IsNullOrEmpty(dtValue))
    Ddt = DateTime.ParseExact(dtValue, "dd-MM-yy", null).AddDays(1).ToShortDateString();

    I hope this helps.


    Please mark this post as answer if it solved your problem. Happy Programming!

    Tuesday, May 29, 2012 5:28 AM
  • Hi vaibhav vijay,

    no need to set any global format for this, these formats will be converted according to the culture you are using, if you not mention any culture to your application it will take system culture by default. So set the culture you want in web.config or where ever you need.

    Let me show you some example here please change it accordingly as per your requirement.

    CultureInfo culture = new CultureInfo(“en-US”);
    string today = DateTime.Now.ToString(“d”,culture);
    

    through out your application your date format will be same.

    Hope it will help you..


    Sai Kumar K (MCP)
    Blog: Sai's Stuff.
    WebSite: SantoshTechnologies.

    • Marked as answer by vaibhavsaral Tuesday, May 29, 2012 7:40 AM
    Tuesday, May 29, 2012 5:30 AM
  • Thanks Sai Kumar Koona

    It works. I am able to get rid of that problem.


    SaiVaibhav@Acumen

    Tuesday, May 29, 2012 7:41 AM