public static class ClsConvertDateTimeDecimal
{
public static DateTime ToDateTime(decimal value)
{
if (value != 0)
{
string[] parts = value.ToString().Replace(',', '.').Split(new char[] { '.' });
int hours = Convert.ToInt32(parts[0]);
int minutes;
if (parts[1] != null)
minutes = Convert.ToInt32(parts[1]);
else
minutes = 0;
if ((hours > 23) || (hours < 0))
{
throw new ArgumentOutOfRangeException("Valor", "El Valor no puede ser superior a 23:59 ni menor que 0");
}
if ((minutes > 59) || (minutes < 0))
{
throw new ArgumentOutOfRangeException("Valor", "El Valor no puede ser superior a 23:59 ni menor que 0");
}
DateTime d = new DateTime(1, 1, 1, hours, minutes, 0);
return d;
}
else
{
return new DateTime(1, 1, 1, 0, 0, 0);
}
}
public static Decimal ToDecimal(DateTime datetime)
{
Decimal d = new decimal();
d = datetime.Hour;
d = d + Convert.ToDecimal((datetime.Minute * 0.01));
return d;
}