Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

checking of correct datetime format is not working

$
0
0

Hi

I want to check the given string value is correct  format for converting into  datetime  variable before to convert into date time variable.  But the value '05/03/2020 8:15:00' is showed as incorrect format . Please can you advise me where is the problem

eg: datetimestring  ='05/03/2020 8:15:00'

                string clockeddate = log.AttendanceDate;
                string timeclock = log.Hrs + ':' + log.Mins;
                string datetimestring = clockeddate + " " + timeclock+":00";

                DateTime dDate;
                bool isCorrectDateFormat =   DateTime.TryParseExact(datetimestring, "dd/MM/yyyy HH:mm:ss",
                    CultureInfo.InvariantCulture, DateTimeStyles.None, out dDate);
                if(isCorrectDateFormat)
                {
                     dDate = Convert.ToDateTime(clockeddate + " " + timeclock);
                }


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>