How to convert datetime to date string string only

Jeff Stiegler 466 Reputation points
2023-06-06T16:19:44.89+00:00

How do I exclude the time element from the code below.

    Beg_Date.ToString("MM/dd/yyyy")

Returns #05/01/2023 12:00:00 AM#

I want only the date...no time.

Developer technologies VB
{count} votes

Accepted answer
  1. Anonymous
    2023-06-06T18:05:16.9866667+00:00

    duplicated post

    0 comments No comments

7 additional answers

Sort by: Most helpful
  1. Anonymous
    2023-06-06T18:01:16.28+00:00

    Hi

    What do you mean by 'Returns #05/01/2023 12:00:00 AM#', returns that to what/where and how? The statement you show does nothing at all until you assign it or use it in some way.

    Also, how is a value assigned to Beg_Date?

    To assign the datetime to a string with the format you show, everything is exactly as you want.

    		Dim Beg_Date As DateTime = Now
    
    		Dim s As String = Beg_Date.ToString("MM/dd/yyyy")
    
    		' s = 06/06/2023
    
    
    1 person found this answer helpful.

  2. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  3. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

  4. thummala bindu 0 Reputation points
    2023-06-06T18:13:35.1633333+00:00

    To convert a datetime object to a date string in Python, you can use the 'strftime()' method.

    This will output the current date in the format YYYY-MM-DD. You can customize the format string according to your desired date format. The %Y represents the four-digit year, %m represents the month, and %d represents the day. You can find more format codes in the Python documentation for strftime().

    If you have a specific datetime object instead of the current datetime, replace current_datetime in the example with your datetime object.

    from datetime import datetime
    
    # Current datetime
    current_datetime = datetime.now()
    
    # Convert datetime to date string
    date_string = current_datetime.strftime('%Y-%m-%d')
    
    print(date_string)
    
    
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.