locked
HOW TO DECALRE DATE IN VB.NET RRS feed

  • Question

  • User1449453972 posted

    HOW DO I DECLARE IN VB.NET  DT AS TYPE DATE WITH FORMAT DD/MM/YYYY

    DIM DT AS ??

    Tuesday, May 21, 2013 6:15 AM

Answers

  • User1320044578 posted
    DIM DT AS DateTime

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 21, 2013 6:26 AM
  • User-448512826 posted

    HOW DO I DECLARE IN VB.NET  DT AS TYPE DATE WITH FORMAT DD/MM/YYYY

    try

    Dim d As DateTime = Format(Datetime.Now, "MM-dd-yyyy")
    or
    dim d as datetime=DateTime.Now("dd/MM/yyyy")



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 21, 2013 7:42 AM
  • User281315223 posted

    By default a DateTime object will not handle any formatting (such as DD/MM/YYYY etc) as that will be handled depending on how you elect to output it through the .ToString() method as seen below : 

    'Create a DateTime object'
    Dim dt As DateTime = DateTime.Now
    
    'You can use the .ToString() method to handle how you would like to format your Date'
    Dim dtString As String = dt.ToString("dd/MM/yyyy")

    If you would like more information on how you can format DateTime objects, you can see the following link on handling Custom Date and Time Formatting : 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 21, 2013 11:11 AM

All replies

  • User309602797 posted

    try this -

    Dim yourDate As String = DateTime.Now.ToString("dd/MM/yyyy")

    You can also use DateTime.TryParseExact Method or DateTime.ParseExact Method to convert date in required format 

    http://stackoverflow.com/questions/4327895/converting-date-string-to-datetime-format-vb-net

    Tuesday, May 21, 2013 6:26 AM
  • User1320044578 posted
    DIM DT AS DateTime

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 21, 2013 6:26 AM
  • User-800912061 posted

    Please try like this.

    Dim Now As DateTime = DateTime.Now

    Or

    dim date_time as DateTime = Date.ParseExact(txtDateAdded.Text, "dd/MM/yyyy", Nothing).Date

    Or refer to below links.

    http://www.dotnetperls.com/datetime-parseexact

    http://blog.stevex.net/parsing-dates-and-times-in-net/

    Tuesday, May 21, 2013 6:30 AM
  • User-448512826 posted

    HOW DO I DECLARE IN VB.NET  DT AS TYPE DATE WITH FORMAT DD/MM/YYYY

    try

    Dim d As DateTime = Format(Datetime.Now, "MM-dd-yyyy")
    or
    dim d as datetime=DateTime.Now("dd/MM/yyyy")



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 21, 2013 7:42 AM
  • User281315223 posted

    By default a DateTime object will not handle any formatting (such as DD/MM/YYYY etc) as that will be handled depending on how you elect to output it through the .ToString() method as seen below : 

    'Create a DateTime object'
    Dim dt As DateTime = DateTime.Now
    
    'You can use the .ToString() method to handle how you would like to format your Date'
    Dim dtString As String = dt.ToString("dd/MM/yyyy")

    If you would like more information on how you can format DateTime objects, you can see the following link on handling Custom Date and Time Formatting : 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, May 21, 2013 11:11 AM