Click here to Skip to main content
15,912,504 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,


I want to use custom date variable formats without changing the regional settings.

ex:
Dim mydate as date

mydate = "30/05/2014"


It shows the following error
"Conversion from string "30/05/2014" to type 'Date' is not valid."

when my short date format is MM/yyyy/dd.



How to rectify the error without changing short date format in Regional Settings.
Posted

MyDate = CDate("20/05/2014").ToShortDateString

OR
MyDate = Convert.ToDateTime("20/05/2014").ToShortDateString
 
Share this answer
 
Comments
kgmmurugesh 16-Jun-14 3:25am    
It shows the following error
Could not determine the order of year, month, and date from 'MM/yyyy/dd'.
try this:-

VB
Dim mydate as date

mydate= DateTime.ParseExact("30/05/2014", "MM/yyyy/dd",CultureInfo.InvariantCulture);
 
Share this answer
 
Comments
kgmmurugesh 16-Jun-14 4:17am    
Thanks, It works well. What is need is mydate should be "30/05/2014". Now my date is "05/30/2014", I want mydate format should be "dd/mm/yyyy"
SimpleDateFormat sdf = new SimpleDateFormat("MM:yyyy:dd");
Date date = new Date();
String time = sdf.format(date);
System.out.println(time);
 
Share this answer
 
v3

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