简体   繁体   中英

datetime comparison on iis7

i am creating an web application, where i need to compare two date and time (even second also).

i am using following code for that:

//Check for delete button
                DateTime dtmEndDate;
                DateTime.TryParse(dtCommunication.Rows[0]["DateEnd"].ToString(), out dtmEndDate);

                if (dtmEndDate<=DateTime.Now)
                {

                //}
                //if DateTime.Compare(DateTime.Now.ToLocalTime(),dtmEndDate.ToLocalTime()) >= 0)
                //{
                    btnSend.Visible = false;
                    btnBack.Visible = false;

                    btnDelete.Visible = true;
                    btnCancel.Visible = true;         
                }

if EndDate datetime has been elapsed, then it will go inside if block.

This working fine locally, but when i upload the code on the server, its not working accordingly. How i can handle this?


Example:
dtmEndDate= 12/27/2012 7:00 PM
Current Indian time =12/27/2012 8:00 PM
Current Sever Time=12/27/2012 8:30 AM

above are the scenario.

TryParse returns false if it tried and failed.

DateTime dtmEndDate;
if (DateTime.TryParse(dtCommunication.Rows[0]["DateEnd"].ToString(), out dtmEndDate))
{
   // okey dokey
}
else
{
   throw new SomeException(String.Format("{0} is not a valid date",dtCommunication.Rows[0]["DateEnd"].ToString());
}

would be a good start. A guess would be dateend is blank, not a date or not a date in a format the application is set up for. Have a look at ParseExact, and the System.Globalisation namespace's CultureInfo.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM