duplicated post
How to convert datetime to date string string only
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
7 additional answers
Sort by: Most helpful
-
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
-
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
-
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
-
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 forstrftime()
.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)