473,422 Members | 1,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,422 software developers and data experts.

DateTime Conversion Nightmare


I'm trying to convert into friendly format the "LastModified" property
of an object returned via WMI from remote servers. Every attempt to
manipulate that using DateTime has bombed with "specified cast not
valid" errors, etc. Here is the code:

for(i=0;i<SCOREArray.GetUpperBound(0);i++)
{

ConnectionOptions oConn = new ConnectionOptions();
oConn.Username =
oConn.Password =

System.Management.ManagementScope oMs = new
System.Management.ManagementScope("\\\\" + SCOREArray[i] +
"\\root\\cimv2", oConn);
System.Management.ObjectQuery oQuery = new
System.Management.ObjectQuery("select * FROM CIM_Datafile WHERE Name =
'c:\\\\winnt\\\\memory.dmp'");
ManagementObjectSearcher oSearcher = new
ManagementObjectSearcher(oMs,oQuery);
ManagementObjectCollection oReturnCollection = oSearcher.Get();

foreach( ManagementObject oReturn in oReturnCollection )
{
try
{

ListBox1.Items.Add(SCOREArray[i] + " - Modify date is : " +
(oReturn["LastModified"].ToString()));
}
catch(System.Exception gen_ex)
{ ListBox1.Items.Add(SCOREArray[i] + gen_ex.Message);
}
An example of the output of this property is
"20050105160751.664062-360". I'm having a terrible time converting that
into a user-friendly date.

Any assistance appreciated.

chris

Nov 17 '05 #1
3 5502
Take a look at this:

http://msdn.microsoft.com/library/de...arsetopic2.asp

--

Thanks,
Yunus Emre ALPÖZEN
BSc, MCSD.NET

"Chris Malone" <pe********@hotmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...

I'm trying to convert into friendly format the "LastModified" property
of an object returned via WMI from remote servers. Every attempt to
manipulate that using DateTime has bombed with "specified cast not
valid" errors, etc. Here is the code:

for(i=0;i<SCOREArray.GetUpperBound(0);i++)
{

ConnectionOptions oConn = new ConnectionOptions();
oConn.Username =
oConn.Password =

System.Management.ManagementScope oMs = new
System.Management.ManagementScope("\\\\" + SCOREArray[i] +
"\\root\\cimv2", oConn);
System.Management.ObjectQuery oQuery = new
System.Management.ObjectQuery("select * FROM CIM_Datafile WHERE Name =
'c:\\\\winnt\\\\memory.dmp'");
ManagementObjectSearcher oSearcher = new
ManagementObjectSearcher(oMs,oQuery);
ManagementObjectCollection oReturnCollection = oSearcher.Get();

foreach( ManagementObject oReturn in oReturnCollection )
{
try
{

ListBox1.Items.Add(SCOREArray[i] + " - Modify date is : " +
(oReturn["LastModified"].ToString()));
}
catch(System.Exception gen_ex)
{ ListBox1.Items.Add(SCOREArray[i] + gen_ex.Message);
}
An example of the output of this property is
"20050105160751.664062-360". I'm having a terrible time converting that
into a user-friendly date.

Any assistance appreciated.

chris

Nov 17 '05 #2
Hi,

I would use the mgmtclassgen generator from VS [see
http://msdn.microsoft.com/library/de...lassgenexe.asp ]
, export a class containing the WBEMDateTime and cut and paste the
conversion code .... That's what I've done.

Best regards,
Manfred Braun

(Private)
Mannheim
Germany

mailto:_m*************@manfbraun.de
(Remove the anti-spam-underscore to mail me!)

"Chris Malone" <pe********@hotmail.com> wrote in message
news:11**********************@g44g2000cwa.googlegr oups.com...

I'm trying to convert into friendly format the "LastModified" property
of an object returned via WMI from remote servers. Every attempt to
manipulate that using DateTime has bombed with "specified cast not
valid" errors, etc. Here is the code:

for(i=0;i<SCOREArray.GetUpperBound(0);i++)
{

ConnectionOptions oConn = new ConnectionOptions();
oConn.Username =
oConn.Password =

System.Management.ManagementScope oMs = new
System.Management.ManagementScope("\\\\" + SCOREArray[i] +
"\\root\\cimv2", oConn);
System.Management.ObjectQuery oQuery = new
System.Management.ObjectQuery("select * FROM CIM_Datafile WHERE Name =
'c:\\\\winnt\\\\memory.dmp'");
ManagementObjectSearcher oSearcher = new
ManagementObjectSearcher(oMs,oQuery);
ManagementObjectCollection oReturnCollection = oSearcher.Get();

foreach( ManagementObject oReturn in oReturnCollection )
{
try
{

ListBox1.Items.Add(SCOREArray[i] + " - Modify date is : " +
(oReturn["LastModified"].ToString()));
}
catch(System.Exception gen_ex)
{ ListBox1.Items.Add(SCOREArray[i] + gen_ex.Message);
}
An example of the output of this property is
"20050105160751.664062-360". I'm having a terrible time converting that
into a user-friendly date.

Any assistance appreciated.

chris

Nov 17 '05 #3
Actually I figured it out over the weekend and used
ManagementDateTimeConverter.ToDateTime. This is exactly what I needed.

chris

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: John Hunter | last post by:
>>> from datetime import date >>> dt = date(1005,1,1) >>> print dt.strftime('%Y') Traceback (most recent call last): File "<stdin>", line 1, in ? ValueError: year=1005 is before 1900; the...
3
by: sunny076 | last post by:
Hi, I am trying to convert from Julian to Gregorian data in C#. I was exploring teh JulianCalendar and Gregorian calendar classes but still not sure how I can do it. For example, the Julian date...
26
by: Reny J Joseph Thuthikattu | last post by:
Hi, I have a variabe in the format of 'DD-MON-YYYY HH:MI AM' .I want to add a miniute to it.How can i do that? by manipulation i want to make '01-JUNE-2004 11:59 PM' to '02-JUNE-2004 12:00 AM'...
11
by: Cor Ligthert | last post by:
Hello everybody, Jay and Herfried are telling me every time when I use CDate that using the datetime.parseexact is always the best way to do String to datetime conversions. They don't tell why...
1
by: Untitled | last post by:
I have an application that stores all DateTime inforamtion in UTC. However, this application will be accessed from arround the world. I would like my users to be able to specify their prefered...
9
by: Hrvoje Voda | last post by:
How to convert text from textbox "12.05.1977" into "12/05/1977"? and also check if the text is in right format before converting? Hrcko
2
by: Mike | last post by:
Hi, I have DateTime filed in db table. I'd like to search my db based on DateTime filed, actually to list all rows with particular date, for e.g. 16.11.2007... I send string to method for....
11
by: =?Utf-8?B?UGFvbG8=?= | last post by:
I have a SQL database table with rows in which the primary key is a DateTime type (although I don't use the Time part). Have added numerous rows and now want to delete one so I enter the date...
1
Manikgisl
by: Manikgisl | last post by:
But the problem is we have dates in Varchar instead Datetime While Converting Varchar To Datetime All four formats are unable to Convert ie select Convert(Datetime,'18-11-2008 2:35:19...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.