1 Reply Latest reply on Apr 26, 2017 2:42 AM by martinluth123

    Date only and Time only into a DateTime field?

    SusanJS Specialist

      Has anyone taken a date only and a time only field and combined them into a DateTime field?  Looking for a fairly simple way to do this.  It doesn't seem to be a matter of just concatenating into a text field with a ToString() then converting it back because the time field seems to set a default date of 1/1/1970.  Seems like it should be simple, but it isn't.

        • 1. Re: Date only and Time only into a DateTime field?
          martinluth123 Rookie

          Step 1: Create a calculated field that combines the date and time columns
              In Tableau Desktop, connect to the data source. For this example, use the attached data source, Fruit Sales.xlsx.
              Select Analysis > Create Calculated Field.
              In the Create Calculated Field dialog box, do the following:
                  In the Name text box, enter a name for the calculated field. For this example, use Date + Time.
                  In the Formula text box, enter the following:
                  'hour', DATEPART('hour', [Time Sold]), DATEADD(
                  'minute', DATEPART('minute', [Time Sold]), DATEADD(
                  'second', DATEPART('second', [Time Sold]), [Date Sold])))
                  Click OK.
              The date and time columns are now combined into a single field and you can use the built-in date parts to drill down the datetime hierarchy.
          Step 2: Create the final view
              In the Data window, right-click the Date + Time field, and then drag it to the Rows shelf.
              In the Drop Field dialog box, click Date + Time (Discrete), and then click OK.

          Check for essay writing service reviews