Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In vb.net I have an object
VB
strEnteredDate
which is holding a date like this 2018-03-29T10:26:20
I would like to format this date to look like this 2018-03-29.
How do I do it?
What I have tried here below is getting an option strict error.

What I have tried:

strEnteredDate.ToString("yyyy-MM-ddThh: mm : ss").Replace("T", "hh", ":", "mm", ":", "ss"))
Posted
Updated 20-Apr-18 10:39am

Did you try
VB
strEnteredDate.ToString("yyyy-MM-dd")
 
Share this answer
 
Comments
Member 11403304 20-Apr-18 15:55pm    
This is giving the following error message. Option Strict On disallows implicit from 'string' to IFormatProvider
Patrice T 20-Apr-18 16:04pm    
Show some code that we can run.
I suppose that your entered 'Object' strEnteredDate is allready a string.
So you only need to cut the left 10 chars from this string and write it into a new string (or the same).
For example like this :
VB
strEnteredDate = strEnteredDate.substring(0,10)
 
Share this answer
 
Comments
Member 11403304 20-Apr-18 17:02pm    
Thanks. You are right. My object is already a string. It is working now.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900