Results 1 to 4 of 4

Thread: [2.0] Formating DateTime

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2000
    Location
    Cairo, Egypt
    Posts
    126

    Question [2.0] Formating DateTime

    Hi All;
    I just moved from log time developing with VB and I face some problems in some functions from VB to C# like formating the DateTime specially the Time from 12 hours to 24 hours or vice versa and formating the Year from 2 digits to 4 digits and vice versa.

  2. #2
    Lively Member
    Join Date
    Oct 2006
    Location
    USA
    Posts
    122

    Re: [2.0] Formating DateTime

    I am not sure about the year. However, I would think you could use the padleft command to format that year.

  3. #3
    Fanatic Member daimous's Avatar
    Join Date
    Aug 2005
    Posts
    657

    Re: [2.0] Formating DateTime

    This might Be of Help.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] Formating DateTime

    You can convert a DateTime to a string representation by calling its ToLongDateString, ToLongTimeString, ToShortDateString, ToShortTimeString or ToString methods. The first four will use the formats specified in the system's regional settings. The fourth will also use the standard format specified in regional settings if no parameter is specified. You can also specify a format string that conforms to any of the standard format strings or custom format strings for date and time values.

    To convert strings to DateTimes you would use DateTime.Parse, ParseExact, TryParse or TryParseExact, depending on whether you were sure the values was valid and whether it used a standard format or not.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width