putting PM in a DateTime format in a winform

Posted on 2012-08-28
Last Modified: 2012-08-28
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
Question by:r3nder
    LVL 20

    Accepted Solution

    DateTime tempend = DateTime.Today.AddDays(1).AddSeconds(-1);
    string end = tempend.ToString();
    LVL 6

    Author Closing Comment

    Thank you - worked like a champ - didnt think of adding a day and minusing 1 second :)

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Suggested Solutions

    A short article about problems I had with the new location API and permissions in Marshmallow
    Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now