• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 783
  • Last Modified:

putting PM in a DateTime format in a winform

I have a sql statement that I am trying to put a start date and an end date into. The startdate is DateTime.Today - because that returns MM/dd/yyyy 12:00:00 AM
I need the end date to be MM/dd/yyyy 11:59:59 PM  - How is this done? When I use tt it returns AM
        private void radButton1_Click(object sender, EventArgs e)

            DateTime tempend = DateTime.Today;
            string format = "MM/dd/yyy 11:59:59 tt";

            string end = tempend.ToString(format);
            DateTime start = DateTime.Today;

            string newuserid = iuserid.ToString();
            string conString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
            string sqlstr = "delete from ARoles where useruid ='" + newuserid + "' and LastEditDate between '" + start + "' and  '" + end + "'";
            HelperClasses.SqlHelper.ExecuteNonQuery(conString, CommandType.Text, sqlstr);

Open in new window

I would appreciate the help
Thanks R3nder
1 Solution
DateTime tempend = DateTime.Today.AddDays(1).AddSeconds(-1);
string end = tempend.ToString();
r3nderAuthor Commented:
Thank you - worked like a champ - didnt think of adding a day and minusing 1 second :)

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now