473,378 Members | 1,446 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,378 software developers and data experts.

Converting Cobol date to .Net DateTime

1
Hello!

I'm reading binary file exported from mainframe's tape. There used COBOL data types. Some date fields are represented by PIC '9999', but some - by FIXED(7). The first one I have recognized and converted quickly, but the second one is a problem.

I found the conversion algorithm (http://www.thescripts.com/forum/thread267116.html) to convert FIXED(7) to UInt32 value, but now I don't know how to construct .Net DateTime from this UInt32.

Have somebody had deal with this problem? I tried distinct binary loayouts of date (http://webster.cs.ucr.edu/AoA/Windows/HTML/DataRepresentationa7.html), but I didn't get result seeming correctly.


I tried to get UInt32 by two ways:

private static UInt32 IntFromFixed( Byte[] raw )
{
Int32 res = 0;
Byte b;
for( Int32 i = 0; i < raw.Length - 1; ++i )
{
res <<= 8;
b = raw[ i ];
res += ((b & 0xF) + (b >> 4)*10);
}
b = raw[ raw.Length - 1 ];
res <<= 8;
res += ((b >> 4)*10);
b &= 0xF;
if( b == 0xD )
res = -res;

return res;
}

OR
private static UInt32 IntFromFixed( Byte[] raw )
{
String res = "";
Byte b;
for( Int32 i = 0; i < raw.Length - 1; ++i )
{
b = raw[ i ];
res += ((b & 0xF) + (b >> 4)*10).ToString();
}
b = raw[ raw.Length - 1 ];
res += ((b >> 4)*10).ToString();
b &= 0xF;
if( b == 0xD )
res = "-" + res;

return UInt32.Parse( res );
}

And I tried to construct DateTime:

UInt32 dc = IntFromFixed( raw );
UInt32 y = (dc & 0x7F), m = (dc & 0xF000) >> 12, d = (dc & 0xF80) >> 7;
if( y == 0 )
return (DateTime?)null;
return (DateTime?)new DateTime( 1900 + (int)y, (int)m, (int)d );



Thanks and good luck!
Feb 22 '07 #1
0 1104

Sign in to post your reply or Sign up for a free account.

Similar topics

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...
2
by: - Steve - | last post by:
I'm taking the value of the expire date out of an AD account (accountExpires attribute) and passing it into this function. static DateTime LargeIntToDateTime(ActiveDs.LargeInteger li) { long...
1
by: Andrew Baker | last post by:
this seems to be an SQL Server error but I cant work out how it is occuring. Itr is also after 3am and I cant keep working but need to demo by tomorrow. TIA. The code is: Private Sub...
8
by: Mika M | last post by:
Is there better way to convert integer type date into DateTime type date as doing like code below? Dim intDate As Integer = 20051019 Dim dte As DateTime = New DateTime( _...
3
by: NateM | last post by:
How do I convert any given date into a milliseconds value that represents the number of milliseconds that have passed since January 1, 1970 00:00:00.000 GMT? Is there an easy way to do this like...
15
by: dm1608 | last post by:
We have a number of COBOL programs, and some were currently developing, that simply read TEXT based reports and scrap the reports for various information. I'm curious to know if anyone has...
9
by: Alok yadav | last post by:
i am using a webservice in which a method is serach. i use this method which accept a argument of date type in dd/MM/yyyy formate. i have a textbox which accept the date from the user, when i...
18
by: Dirk Hagemann | last post by:
Hello, From a zone-file of a Microsoft Active Directory integrated DNS server I get the date/time of the dynamic update entries in a format, which is as far as I know the hours since january 1st...
11
by: Keith Hughitt | last post by:
Hi, I am having a little trouble figuring out how to convert a python datetime to UTC. I have a UTC date (e.g. 2008-07-11 00:00:00). I would like to create a UTC date so that when I send it to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...

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.