How to check datetime
If you use vb.net, this is not a problem for you but I think some people using c# have a trouble in there.Now, I will explain how to check datetime.I will explain two ways.
first way is so easy.you should add this method and use it.
public bool isDate(string date) {
try{
DateTime dt=DateTime.parse(date);
return true;
}
catch(Exception ex){
return false;
}
}
But this is not a good way.How is second.Second way is so beauty.
public bool checkDate(string date){
DateTime d;
return DateTime.TryParse(date,d);
}
first way is so easy.you should add this method and use it.
public bool isDate(string date) {
try{
DateTime dt=DateTime.parse(date);
return true;
}
catch(Exception ex){
return false;
}
}
But this is not a good way.How is second.Second way is so beauty.
public bool checkDate(string date){
DateTime d;
return DateTime.TryParse(date,d);
}
1 comment:
TryParse! smarter way
Post a Comment