locked
Date Format (YYYY/MM/DD) From (MM/DD/YYYY) RRS feed

  • Question

  • User-1925328050 posted

    I am very new to asp.net (started this week)

     I have the following line FormatDateTime(dsEdit.FieldValue("BDateStart", Container),2) which is currently displaying the date as MM/DD/YYYY when I need YYYY/MM/DD to suit my database (MySQL)

     How can I go about formatting the date to suit my needs?

     Thankyou

    Tuesday, April 24, 2007 12:39 AM

Answers

  • User2082643792 posted

    DateTime dt = DateTime.Now;

    Response.Write(dt.ToString("yyyy/MM/dd"));

     

    Please mark this post as RESOLVED.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 24, 2007 2:19 AM

All replies

  • User-319574463 posted

    With FormatDateTimeyou have a limited range of formatting options see http://msdn.microsoft.com/en-us/library/a912f2a0(VS.80).aspx

    Change FormatDateTime(dsEdit.FieldValue("BDateStart", Container),2)
    to dsEdit.FieldValue("BDateStart", Container).ToString("yyyy/MM/dd")

     

     

    Tuesday, April 24, 2007 2:15 AM
  • User-319574463 posted

    With FormatDateTimeyou have a limited range of formatting options see http://msdn.microsoft.com/en-us/library/a912f2a0(VS.80).aspx

    Change FormatDateTime(dsEdit.FieldValue("BDateStart", Container),2)
    to dsEdit.FieldValue("BDateStart", Container).ToString("yyyy/MM/dd")

     

     

    Tuesday, April 24, 2007 2:17 AM
  • User-319574463 posted

    With FormatDateTimeyou have a limited range of formatting options see http://msdn.microsoft.com/en-us/library/a912f2a0(VS.80).aspx

    Change FormatDateTime(dsEdit.FieldValue("BDateStart", Container),2)
    to dsEdit.FieldValue("BDateStart", Container).ToString("yyyy/MM/dd")

     

     

    Tuesday, April 24, 2007 2:18 AM
  • User2082643792 posted

    DateTime dt = DateTime.Now;

    Response.Write(dt.ToString("yyyy/MM/dd"));

     

    Please mark this post as RESOLVED.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 24, 2007 2:19 AM
  • User-1925328050 posted

    Thankyou for your reply.

     I tried the above and got the following error:

     Compiler Error Message: BC30311: Value of type 'String' cannot be converted to 'System.IFormatProvider'.

     On the line which had the change?

     

    Tuesday, April 24, 2007 5:53 PM
  • User-319574463 posted

     

    Change

     dsEdit.FieldValue("BDateStart", Container).ToString("yyyy/MM/dd")

    to

    System.IFormatProvider xIFormatProvider = new CultureInfo("en-GB", true);
    dsEdit.FieldValue("BDateStart", Container).ToString(xIFormatProvider,"yyyy/MM/dd")

    Wednesday, April 25, 2007 7:32 AM
  • User674385744 posted

     MM/DD/YYYY - YYYY/MM/DD to suit my database (MySQL)

    Hi,

           U can do it using this piece of code ..

               Session.LCID = proper code .. // here u have to fill the exact code which wil match for YYYY/MM/DD

           Check this URL .. http://www.4guysfromrolla.com/webtech/111299-1.shtml and http://www.sql-server-helper.com/tips/date-formats.aspx

           Hope this may resolve ur problem ... 

    Wednesday, April 25, 2007 7:54 AM
  • User-1925328050 posted

    Thanks, I tried that and got the following error, I'm sure it's probably a simple thing but I have only just started asp.net this week, thanks.

    Compiler Error Message: BC30691: 'IFormatProvider' is a type in 'System' and cannot be used as an expression.

    Wednesday, April 25, 2007 6:07 PM
  • User-319574463 posted

    Try

          CultureInfo xIFormatProvider = new CultureInfo("en-GB", true);
          dsEdit.FieldValue("BDateStart", Container).ToString(xIFormatProvider,"yyyy/MM/dd");

    Wednesday, April 25, 2007 6:48 PM
  • User-1925328050 posted

    Thanks, I got this error with that:

    Compiler Error Message: BC30451: Name 'CultureInfo' is not declared.

    Wednesday, April 25, 2007 8:36 PM
  • User-319574463 posted

    Add

    using System.Globalization;

    to your using statements 

    Thursday, April 26, 2007 1:57 AM
  • User-1925328050 posted

    Got it working as required:

     

    1. Dim dsDate As DateTime = dsEdit.FieldValue("BDateStart", Container)
    2. Dim myDate As String = dsDate.ToString("yyyy/MM/dd")
    Thursday, April 26, 2007 5:30 PM
  • User-60872656 posted

    i am .net learner and i am inserting date into database table in mysql ....... so i want to set the date format as yyyy-mm-dd in asp.net ....... i am using vbscript plz can anyone help me in this regard

    thanks

    avinash 

    Thursday, January 31, 2008 5:07 AM
  • User-519843487 posted

     i will give you the most simple solution

    put this in web.config

     <globalization culture="he-IL"></globalization>

    and thats it, its all done

     

    Friday, June 12, 2009 1:12 PM
  • User-319574463 posted

     he-IL is Hebrew in Israel

    hi-IN is Hindi in India

    You can get a list of culture codes from http://msdn.microsoft.com/en-us/goglobal/bb896001.aspx

    Saturday, June 13, 2009 5:32 AM