0

NET and I working on a program where I take some data from database and try to compare with the DateTime field. For Example I have certain documents in the SEIBEL database and I want expiration date of those documents and compare the with current date and time and fire message accordingly. But somehow I an unable to compare them.

This is the sql query in asp.net that I am running

private static readonly string GET_PROVIDER_DOCUMENTS = @"
select sc.row_id, 
       doc.created as created_date, 
       doc.attrib_04 as document_type, 
       doc.attrib_47 as exipration_date,
       att.row_id    as document_row_id,
       att.file_name || '.' || att.file_ext as file_name
  from siebel.s_org_ext sc
  join siebel.s_org_ext_xm doc 
    on doc.par_row_id = sc.row_id
   and doc.type = 'SCLicenseInfo'
   and doc.attrib_35 = 'Expiration Date'
   and doc.attrib_04 in ('Certificate of Insurance', 'Master Service Agreement')
  left join siebel.s_accnt_att att on att.comments = doc.row_id
 where sc.row_id = :sc_row_id
";

and this where I trying to get expiration date from database

ExpirationDate = ConvertExpirationDate(dr["exipration_date"].ToString()),

If anybody has any idea about it it would great. Thanks in advance

John
  • 73
  • 1
  • 8

3 Answers3

0

Have you looked at the TryParse method on a DateTime object?

https://msdn.microsoft.com/en-us/library/system.datetime.tryparse(v=vs.110).aspx

May be suitable for your needs though I believe it will depend on the format your date is stored in.

Jelleh
  • 116
  • 7
0

Assuming you are successfully getting the datetime from the datebase and storing it as a string called ExpirationDate:

DateTime date1 = Convert.ToDateTime(ExpirationDate);
Datetime date2 = new Datetime(---)//desired date to compare with.

if(DateTime.Compare(date1,date2)==0)
{
    // They're equal.
}
else
{
    // Not equal.  
}

Converting: https://msdn.microsoft.com/en-us/library/system.convert.todatetime(v=vs.110).aspx

Comparing: https://msdn.microsoft.com/en-us/library/system.datetime.compare(v=vs.110).aspx

  • Hi I tried your solution but I am getting the error "the name "ExpirationDate" does not exist in the current context" I think because it is declared as public DateTime ExpirationDate { get; set; }, it looks like string but behaves differently – John Feb 11 '16 at 20:34
0

Alternatively you could compare the day / month / year components of the date like this :

DateTime today = DateTime.Today;
if(ExpirationDate.Year == today.Year &&
ExpirationDate.Month = today.Month && ExpirationDate.Day = today.Day )
Le Woogush
  • 375
  • 2
  • 16