To Short Date Time
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace NetworkAssetManager.WMI { class WMIUtil { public static DateTime ToShortDateTime(string dmtfDate) { DateTime initializer = DateTime.MinValue; int year = initializer.Year; int month = initializer.Month; int day = initializer.Day; string dmtf = dmtfDate; DateTime datetime = DateTime.MinValue; string tempString = string.Empty; if ((dmtf == null)) { return DateTime.MinValue; } if ((dmtf.Length == 0)) { return DateTime.MinValue; } if ((dmtf.Length != 8)) { return DateTime.MinValue; } try { tempString = dmtf.Substring(0, 4); if (("****" != tempString)) { year = int.Parse(tempString); } tempString = dmtf.Substring(4, 2); if (("**" != tempString)) { month = int.Parse(tempString); } tempString = dmtf.Substring(6, 2); if (("**" != tempString)) { day = int.Parse(tempString); } if (year < 0 || month < 0 || day < 0 ) { return DateTime.MinValue; } } catch (Exception) { return DateTime.MinValue; } datetime = new DateTime(year, month, day, 0, 0, 0, 0); return datetime; } } }