none
Not to use system date / time in my VB.NET App RRS feed

  • Question

  • how can i ignore system date and time in my VB.Net app and use my own. say my own date format.

    i need this for deploying the application on different machines with different date time format and the saving of date time may not be uniform across all plateforms.

    like some machines may have date format mm/dd/yyyy some may have dd/mm/yyyy.

    and i want my own uniform format across all the machines. how to accomplish that in VB.NET????

    Monday, May 31, 2010 5:03 AM

Answers

All replies

  • You need the similar format only for display purposes? Normally you use a format string to accomplish this goal! You can define the culture and the format or a culture independent format. more on msdn

     

    var date = DateTime.Now; 
    // Displays e.g. Monday, May 31, 2010 6:30 AM  
    var d1 = date.ToString("f", CultureInfo.CreateSpecificCulture("en-US")
    // Displays e.g. 31.05.2010
    var d2 = date.ToString("dd.MM.yyyy");  


    Mattia Baldinger http://www.code-in.net/
    Monday, May 31, 2010 5:57 AM
  • thats fine but i want to save the same format into SQL Server database.

    by default the sql server database saves dates like YYYY-MM-dd hh:mm:ss

    can the default format be changed there or do i need to change the format for reporting / other purposes as in the above example.

    Monday, May 31, 2010 6:12 AM
  • The default format of the sql server database will doesn't effect the format which is used on the client. A DateTime object stored can be stored in a database or be read from a database, independent from how it is displayed as string.
    Mattia Baldinger http://www.code-in.net/
    Monday, May 31, 2010 6:24 AM