![]() |
General Programming »
Date and Time »
Tools
Beginner
License: The Code Project Open License (CPOL)
Seagate Date Code CalculatorBy Paw JershaugeHow to get the date 20 November 2005 from the number 06212. |
C# (C# 2.0).NET 2.0, Win2K, WinXP, Win2003, VistaVS2005, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||

The code described in this article helps users convert Seagate's (the hard drive manufacture) date code to a DateTime value.
This article is based on this documentation.
I had to check some hard drives for warranty, and found myself checking very old hard drives.
Here is the actual code invloved:
private DateTime datecalc;
private string _datecode;
public string DateCode
{
get { return _datecode; }
set
{
int _CodeYear = 0;
byte _CodeWeek = 0;
byte _CodeDayOfWeek = 0;
_datecode = value;
if (_datecode.Length == 5)
{
//Get the number of weeks to add
_CodeWeek = Convert.ToByte(_datecode.Substring(2, 2));
//Get the day of the week in the final week
_CodeDayOfWeek = Convert.ToByte(_datecode.Substring(4));
}
else if (_datecode.Length == 4)
{
//Get the number of weeks to add
_CodeWeek = Convert.ToByte(_datecode.Substring(2, 1));
//Get the day of the week in the final week
_CodeDayOfWeek = Convert.ToByte(_datecode.Substring(3));
}
if (_datecode.Length == 4 || _datecode.Length == 5)
{
_CodeWeek--;
_CodeDayOfWeek--;
_CodeYear = (2000 + Convert.ToInt32(_datecode.Substring(0, 2)) - 1);
datecalc = new DateTime(_CodeYear, 7, 1);
datecalc.AddDays(-1);
do { datecalc = datecalc.AddDays(1); }
while (datecalc.DayOfWeek != DayOfWeek.Saturday);
datecalc = datecalc.AddDays((_CodeWeek * 7) + _CodeDayOfWeek);
}
}
}
public DateTime CalculatedDate
{
get { return datecalc; }
}
public SeagateDateCodeCalc()
{
}
public SeagateDateCodeCalc(string dateCode)
{
this.DateCode = dateCode;
}
This is my first submission here, so let me know if I am missing anything.
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 6 Aug 2007 Editor: Smitha Vijayan |
Copyright 2007 by Paw Jershauge Everything else Copyright © CodeProject, 1999-2009 Web11 | Advertise on the Code Project |