How to get the date only on datetime on c# and putnit on database












-2














I was working on an information system that gathers the students information for the teachers. One part of it is outting the value of the datetime picker on the db via command.parameters.addwithvalue. So I'm asking if there is any way to parse the datetime oicker so that there would be only date appearing on the db. Currently, date and time (set date and 12:00:00 am is showing.










share|improve this question






















  • What database are you using?
    – mjwills
    Nov 19 '18 at 13:01






  • 1




    Assuming SQL Server, you want to use the data datatype - docs.microsoft.com/en-us/sql/t-sql/functions/… .
    – mjwills
    Nov 19 '18 at 13:03










  • Why do you need to store only date? You can get datetime from your db and display only this part that you need (date, time or both)
    – Paweł Hemperek
    Nov 19 '18 at 13:03










  • @mjwills Sql2016 on vs2013 itself.
    – Danel Dave Barbuco
    Nov 19 '18 at 13:22










  • @pawet the date mentioned is birthday.
    – Danel Dave Barbuco
    Nov 19 '18 at 13:23
















-2














I was working on an information system that gathers the students information for the teachers. One part of it is outting the value of the datetime picker on the db via command.parameters.addwithvalue. So I'm asking if there is any way to parse the datetime oicker so that there would be only date appearing on the db. Currently, date and time (set date and 12:00:00 am is showing.










share|improve this question






















  • What database are you using?
    – mjwills
    Nov 19 '18 at 13:01






  • 1




    Assuming SQL Server, you want to use the data datatype - docs.microsoft.com/en-us/sql/t-sql/functions/… .
    – mjwills
    Nov 19 '18 at 13:03










  • Why do you need to store only date? You can get datetime from your db and display only this part that you need (date, time or both)
    – Paweł Hemperek
    Nov 19 '18 at 13:03










  • @mjwills Sql2016 on vs2013 itself.
    – Danel Dave Barbuco
    Nov 19 '18 at 13:22










  • @pawet the date mentioned is birthday.
    – Danel Dave Barbuco
    Nov 19 '18 at 13:23














-2












-2








-2







I was working on an information system that gathers the students information for the teachers. One part of it is outting the value of the datetime picker on the db via command.parameters.addwithvalue. So I'm asking if there is any way to parse the datetime oicker so that there would be only date appearing on the db. Currently, date and time (set date and 12:00:00 am is showing.










share|improve this question













I was working on an information system that gathers the students information for the teachers. One part of it is outting the value of the datetime picker on the db via command.parameters.addwithvalue. So I'm asking if there is any way to parse the datetime oicker so that there would be only date appearing on the db. Currently, date and time (set date and 12:00:00 am is showing.







c# sql visual-studio-2013






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 '18 at 13:00









Danel Dave Barbuco

31




31












  • What database are you using?
    – mjwills
    Nov 19 '18 at 13:01






  • 1




    Assuming SQL Server, you want to use the data datatype - docs.microsoft.com/en-us/sql/t-sql/functions/… .
    – mjwills
    Nov 19 '18 at 13:03










  • Why do you need to store only date? You can get datetime from your db and display only this part that you need (date, time or both)
    – Paweł Hemperek
    Nov 19 '18 at 13:03










  • @mjwills Sql2016 on vs2013 itself.
    – Danel Dave Barbuco
    Nov 19 '18 at 13:22










  • @pawet the date mentioned is birthday.
    – Danel Dave Barbuco
    Nov 19 '18 at 13:23


















  • What database are you using?
    – mjwills
    Nov 19 '18 at 13:01






  • 1




    Assuming SQL Server, you want to use the data datatype - docs.microsoft.com/en-us/sql/t-sql/functions/… .
    – mjwills
    Nov 19 '18 at 13:03










  • Why do you need to store only date? You can get datetime from your db and display only this part that you need (date, time or both)
    – Paweł Hemperek
    Nov 19 '18 at 13:03










  • @mjwills Sql2016 on vs2013 itself.
    – Danel Dave Barbuco
    Nov 19 '18 at 13:22










  • @pawet the date mentioned is birthday.
    – Danel Dave Barbuco
    Nov 19 '18 at 13:23
















What database are you using?
– mjwills
Nov 19 '18 at 13:01




What database are you using?
– mjwills
Nov 19 '18 at 13:01




1




1




Assuming SQL Server, you want to use the data datatype - docs.microsoft.com/en-us/sql/t-sql/functions/… .
– mjwills
Nov 19 '18 at 13:03




Assuming SQL Server, you want to use the data datatype - docs.microsoft.com/en-us/sql/t-sql/functions/… .
– mjwills
Nov 19 '18 at 13:03












Why do you need to store only date? You can get datetime from your db and display only this part that you need (date, time or both)
– Paweł Hemperek
Nov 19 '18 at 13:03




Why do you need to store only date? You can get datetime from your db and display only this part that you need (date, time or both)
– Paweł Hemperek
Nov 19 '18 at 13:03












@mjwills Sql2016 on vs2013 itself.
– Danel Dave Barbuco
Nov 19 '18 at 13:22




@mjwills Sql2016 on vs2013 itself.
– Danel Dave Barbuco
Nov 19 '18 at 13:22












@pawet the date mentioned is birthday.
– Danel Dave Barbuco
Nov 19 '18 at 13:23




@pawet the date mentioned is birthday.
– Danel Dave Barbuco
Nov 19 '18 at 13:23












3 Answers
3






active

oldest

votes


















0














In SQL2016, can use the data type date instead of datetime if you don't need the time. If the column's datatype is datetime, you will always have a time associated with it (if you just provide SQL a date for the value, it will set the time to midnight - 00:00:00).



Date and Time datatypes in SQL: https://docs.microsoft.com/en-us/sql/t-sql/functions/date-and-time-data-types-and-functions-transact-sql?view=sql-server-2016#DateandTimeDataTypes



If you don't wan't to (or if you can't) change the data type in the database, then on the C# side you can at least make sure that all the times are normalized to midnight from a datetimepicker by using ControlName.Value.Date where ControlName is the name of your datetimepicker control. (Having all times normalized to midnight can make SQL query writing easier when all you really need is the date but you're stuck with a datetime data type)



DateTime.Date property in .net:
https://docs.microsoft.com/en-us/dotnet/api/system.datetime.date?view=netframework-4.7.2






share|improve this answer





























    0














    Send datetimepicker text to Stored Procedue like varchar parameter with time.
    And parse it in SP like this



        create SP 
    @Date varchar(50)
    as

    declare @DateX smalldatetime

    select @DateX=Convert(smalldatetime,substring(@Date,7,4) +'-' + substring(@Date,4,2) +'-' + substring(@Date,1,2))





    share|improve this answer





























      0














      I Have a C# function for this issue also;



          public String ArrangeDate (string S) 
      {
      FirstPoint = S.IndexOf(".");
      SecondPoint =S.IndexOf(".",FirstPoint+1);
      S= S.Substring(SecondPoint+1,4) + "-" +S.Substring(FirstPoint+1,SecondPoint-FirstPoint-1)+ "-" + S.Substring(0,FirstPoint);
      return S;
      }





      share|improve this answer























        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375233%2fhow-to-get-the-date-only-on-datetime-on-c-sharp-and-putnit-on-database%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        0














        In SQL2016, can use the data type date instead of datetime if you don't need the time. If the column's datatype is datetime, you will always have a time associated with it (if you just provide SQL a date for the value, it will set the time to midnight - 00:00:00).



        Date and Time datatypes in SQL: https://docs.microsoft.com/en-us/sql/t-sql/functions/date-and-time-data-types-and-functions-transact-sql?view=sql-server-2016#DateandTimeDataTypes



        If you don't wan't to (or if you can't) change the data type in the database, then on the C# side you can at least make sure that all the times are normalized to midnight from a datetimepicker by using ControlName.Value.Date where ControlName is the name of your datetimepicker control. (Having all times normalized to midnight can make SQL query writing easier when all you really need is the date but you're stuck with a datetime data type)



        DateTime.Date property in .net:
        https://docs.microsoft.com/en-us/dotnet/api/system.datetime.date?view=netframework-4.7.2






        share|improve this answer


























          0














          In SQL2016, can use the data type date instead of datetime if you don't need the time. If the column's datatype is datetime, you will always have a time associated with it (if you just provide SQL a date for the value, it will set the time to midnight - 00:00:00).



          Date and Time datatypes in SQL: https://docs.microsoft.com/en-us/sql/t-sql/functions/date-and-time-data-types-and-functions-transact-sql?view=sql-server-2016#DateandTimeDataTypes



          If you don't wan't to (or if you can't) change the data type in the database, then on the C# side you can at least make sure that all the times are normalized to midnight from a datetimepicker by using ControlName.Value.Date where ControlName is the name of your datetimepicker control. (Having all times normalized to midnight can make SQL query writing easier when all you really need is the date but you're stuck with a datetime data type)



          DateTime.Date property in .net:
          https://docs.microsoft.com/en-us/dotnet/api/system.datetime.date?view=netframework-4.7.2






          share|improve this answer
























            0












            0








            0






            In SQL2016, can use the data type date instead of datetime if you don't need the time. If the column's datatype is datetime, you will always have a time associated with it (if you just provide SQL a date for the value, it will set the time to midnight - 00:00:00).



            Date and Time datatypes in SQL: https://docs.microsoft.com/en-us/sql/t-sql/functions/date-and-time-data-types-and-functions-transact-sql?view=sql-server-2016#DateandTimeDataTypes



            If you don't wan't to (or if you can't) change the data type in the database, then on the C# side you can at least make sure that all the times are normalized to midnight from a datetimepicker by using ControlName.Value.Date where ControlName is the name of your datetimepicker control. (Having all times normalized to midnight can make SQL query writing easier when all you really need is the date but you're stuck with a datetime data type)



            DateTime.Date property in .net:
            https://docs.microsoft.com/en-us/dotnet/api/system.datetime.date?view=netframework-4.7.2






            share|improve this answer












            In SQL2016, can use the data type date instead of datetime if you don't need the time. If the column's datatype is datetime, you will always have a time associated with it (if you just provide SQL a date for the value, it will set the time to midnight - 00:00:00).



            Date and Time datatypes in SQL: https://docs.microsoft.com/en-us/sql/t-sql/functions/date-and-time-data-types-and-functions-transact-sql?view=sql-server-2016#DateandTimeDataTypes



            If you don't wan't to (or if you can't) change the data type in the database, then on the C# side you can at least make sure that all the times are normalized to midnight from a datetimepicker by using ControlName.Value.Date where ControlName is the name of your datetimepicker control. (Having all times normalized to midnight can make SQL query writing easier when all you really need is the date but you're stuck with a datetime data type)



            DateTime.Date property in .net:
            https://docs.microsoft.com/en-us/dotnet/api/system.datetime.date?view=netframework-4.7.2







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 19 '18 at 23:32









            Shawn Pence

            14114




            14114

























                0














                Send datetimepicker text to Stored Procedue like varchar parameter with time.
                And parse it in SP like this



                    create SP 
                @Date varchar(50)
                as

                declare @DateX smalldatetime

                select @DateX=Convert(smalldatetime,substring(@Date,7,4) +'-' + substring(@Date,4,2) +'-' + substring(@Date,1,2))





                share|improve this answer


























                  0














                  Send datetimepicker text to Stored Procedue like varchar parameter with time.
                  And parse it in SP like this



                      create SP 
                  @Date varchar(50)
                  as

                  declare @DateX smalldatetime

                  select @DateX=Convert(smalldatetime,substring(@Date,7,4) +'-' + substring(@Date,4,2) +'-' + substring(@Date,1,2))





                  share|improve this answer
























                    0












                    0








                    0






                    Send datetimepicker text to Stored Procedue like varchar parameter with time.
                    And parse it in SP like this



                        create SP 
                    @Date varchar(50)
                    as

                    declare @DateX smalldatetime

                    select @DateX=Convert(smalldatetime,substring(@Date,7,4) +'-' + substring(@Date,4,2) +'-' + substring(@Date,1,2))





                    share|improve this answer












                    Send datetimepicker text to Stored Procedue like varchar parameter with time.
                    And parse it in SP like this



                        create SP 
                    @Date varchar(50)
                    as

                    declare @DateX smalldatetime

                    select @DateX=Convert(smalldatetime,substring(@Date,7,4) +'-' + substring(@Date,4,2) +'-' + substring(@Date,1,2))






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 20 '18 at 7:48









                    CAGDAS AYDIN

                    5018




                    5018























                        0














                        I Have a C# function for this issue also;



                            public String ArrangeDate (string S) 
                        {
                        FirstPoint = S.IndexOf(".");
                        SecondPoint =S.IndexOf(".",FirstPoint+1);
                        S= S.Substring(SecondPoint+1,4) + "-" +S.Substring(FirstPoint+1,SecondPoint-FirstPoint-1)+ "-" + S.Substring(0,FirstPoint);
                        return S;
                        }





                        share|improve this answer




























                          0














                          I Have a C# function for this issue also;



                              public String ArrangeDate (string S) 
                          {
                          FirstPoint = S.IndexOf(".");
                          SecondPoint =S.IndexOf(".",FirstPoint+1);
                          S= S.Substring(SecondPoint+1,4) + "-" +S.Substring(FirstPoint+1,SecondPoint-FirstPoint-1)+ "-" + S.Substring(0,FirstPoint);
                          return S;
                          }





                          share|improve this answer


























                            0












                            0








                            0






                            I Have a C# function for this issue also;



                                public String ArrangeDate (string S) 
                            {
                            FirstPoint = S.IndexOf(".");
                            SecondPoint =S.IndexOf(".",FirstPoint+1);
                            S= S.Substring(SecondPoint+1,4) + "-" +S.Substring(FirstPoint+1,SecondPoint-FirstPoint-1)+ "-" + S.Substring(0,FirstPoint);
                            return S;
                            }





                            share|improve this answer














                            I Have a C# function for this issue also;



                                public String ArrangeDate (string S) 
                            {
                            FirstPoint = S.IndexOf(".");
                            SecondPoint =S.IndexOf(".",FirstPoint+1);
                            S= S.Substring(SecondPoint+1,4) + "-" +S.Substring(FirstPoint+1,SecondPoint-FirstPoint-1)+ "-" + S.Substring(0,FirstPoint);
                            return S;
                            }






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Nov 20 '18 at 7:50

























                            answered Nov 20 '18 at 7:40









                            CAGDAS AYDIN

                            5018




                            5018






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.





                                Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                Please pay close attention to the following guidance:


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53375233%2fhow-to-get-the-date-only-on-datetime-on-c-sharp-and-putnit-on-database%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                The term 'EXEC' is not recognized as the name of a cmdlet Powershell

                                NPM command prompt closes immediately [closed]

                                Error binding properties and functions in emscripten