Sortable date on page from 3 seperate columns?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Publisher Bucks
    Confirmed User
    • Oct 2018
    • 1349

    #1

    Tech Sortable date on page from 3 seperate columns?

    Is this possible to do?

    I have a table that contains the following columns in it:

    Month
    Day
    Year

    The output on the page is:

    December 15 2023
    December 21 2023
    December 02 2023

    Is there a way that I can sort that data, if I'm pulling the date itself from 3 seperate columns using 3 echo statements?

    Or, a better way to include the date in form input to put it into the sql table itself making it sortable?
    Extreme Link List - v1.0
  • sarettah
    see you later, I'm gone
    • Oct 2002
    • 14359

    #2
    Originally posted by Publisher Bucks
    Is this possible to do?

    I have a table that contains the following columns in it:

    Month
    Day
    Year

    The output on the page is:

    December 15 2023
    December 21 2023
    December 02 2023

    Is there a way that I can sort that data, if I'm pulling the date itself from 3 seperate columns using 3 echo statements?

    Or, a better way to include the date in form input to put it into the sql table itself making it sortable?
    Why do you have the dates split into month, day and year? And why 3 separate echo statements?

    Anyway, you can concatenate the 3 columns together to make a sortable date.

    Concat function: https://www.w3schools.com/sql/func_mysql_concat.asp


    .
    All cookies cleared!

    Comment

    • Publisher Bucks
      Confirmed User
      • Oct 2018
      • 1349

      #3
      Originally posted by sarettah
      Why do you have the dates split into month, day and year? And why 3 separate echo statements?

      Anyway, you can concatenate the 3 columns together to make a sortable date.

      Concat function: https://www.w3schools.com/sql/func_mysql_concat.asp


      .
      So that when someone uploads they can choose a specific date for publication from a drop down menu, that was honestly the only way i knew how to achieve what i wanted lol

      I'll take a look at that link, thanks
      Extreme Link List - v1.0

      Comment

      • sarettah
        see you later, I'm gone
        • Oct 2002
        • 14359

        #4
        Originally posted by Publisher Bucks
        So that when someone uploads they can choose a specific date for publication from a drop down menu, that was honestly the only way i knew how to achieve what i wanted lol

        I'll take a look at that link, thanks
        Do a pull from the database of id and concatenated date sorted by the concatenated date.

        Make a dropdown using the id as the key and the concatenated date as the display value.

        Then when they pick the date from the dropdown you can retrieve the data using the id.

        .
        All cookies cleared!

        Comment

        • Publisher Bucks
          Confirmed User
          • Oct 2018
          • 1349

          #5
          Originally posted by sarettah
          Do a pull from the database of id and concatenated date sorted by the concatenated date.

          Make a dropdown using the id as the key and the concatenated date as the display value.

          Then when they pick the date from the dropdown you can retrieve the data using the id.

          .
          Awesome, thank you!
          Extreme Link List - v1.0

          Comment

          • fuzebox
            making it rain
            • Oct 2003
            • 22367

            #6
            Originally posted by Publisher Bucks
            So that when someone uploads they can choose a specific date for publication from a drop down menu, that was honestly the only way i knew how to achieve what i wanted lol

            Comment

            • sarettah
              see you later, I'm gone
              • Oct 2002
              • 14359

              #7
              Originally posted by Publisher Bucks
              So that when someone uploads they can choose a specific date for publication from a drop down menu, that was honestly the only way i knew how to achieve what i wanted lol
              I re-read this this morning after Fuzebox quoted you.

              Why not just use a date picker for that?

              <input type="date"

              https://www.w3schools.com/tags/att_input_type_date.asp


              Not sure why you would have the month, year, day tabled in 3 columns if you are using the date as the publishing date for the user to pick from.

              I assumed the table also had other data and you had just split your date up for some reason.

              .
              All cookies cleared!

              Comment

              • Publisher Bucks
                Confirmed User
                • Oct 2018
                • 1349

                #8
                Originally posted by sarettah
                I
                I assumed the table also had other data and you had just split your date up for some reason.

                .
                You assumed correctly, there are a couple of other fields in that table that relate to the document upload also.

                For example, if someone is out who is supposed to publish a document, or the document doesnt pass qc, they can edit the field and set a future date.
                Extreme Link List - v1.0

                Comment

                • sarettah
                  see you later, I'm gone
                  • Oct 2002
                  • 14359

                  #9
                  Originally posted by Publisher Bucks
                  You assumed correctly, there are a couple of other fields in that table that relate to the document upload also.

                  For example, if someone is out who is supposed to publish a document, or the document doesnt pass qc, they can edit the field and set a future date.
                  But why are you splitting your date into 3 columns? Why not just store the date?

                  .
                  All cookies cleared!

                  Comment

                  • Publisher Bucks
                    Confirmed User
                    • Oct 2018
                    • 1349

                    #10
                    Originally posted by sarettah
                    But why are you splitting your date into 3 columns? Why not just store the date?

                    .
                    Because when they publish they are published on specific dates, which correlate to the writing process and publication date of previous titles.

                    Maybe I'm not fully understanding what you are saying about storing the date? Doesnt that just do the same thing when stored?
                    Extreme Link List - v1.0

                    Comment

                    • sarettah
                      see you later, I'm gone
                      • Oct 2002
                      • 14359

                      #11
                      Originally posted by Publisher Bucks
                      Because when they publish they are published on specific dates, which correlate to the writing process and publication date of previous titles.

                      Maybe I'm not fully understanding what you are saying about storing the date? Doesnt that just do the same thing when stored?

                      A date type field in the database is for storing a date. It is just one column, it does not split it into 3 pieces as you described.

                      I have a table that contains the following columns in it:

                      Month
                      Day
                      Year
                      https://dev.mysql.com/doc/refman/8.0/en/datetime.html

                      The DATE type is used for values with a date part but no time part. MySQL retrieves and displays DATE values in 'YYYY-MM-DD' format. The supported range is '1000-01-01' to '9999-12-31'.
                      So you would have the publish date as a date field in the db table.

                      On your recipe add/edit screen you would have the date as an input field on the screen.

                      On an add the field would be blank and the user would enter or pick the date for publishing. On the edit field, once the record was retrieved you would have the field populated with the current publish date and the user would be able to change it.

                      .
                      All cookies cleared!

                      Comment

                      • Publisher Bucks
                        Confirmed User
                        • Oct 2018
                        • 1349

                        #12
                        Originally posted by sarettah
                        On an add the field would be blank and the user would enter or pick the date for publishing. On the edit field, once the record was retrieved you would have the field populated with the current publish date and the user would be able to change it.

                        .
                        Oh okay, I see what you're saying now, okay let me have a play about, that seems like it would actually be much simpler, thank you!
                        Extreme Link List - v1.0

                        Comment

                        Working...