How do you create a new DateTime since Ecto.DateTime was deprecated?How can I get the current operating system name in Elixir?How do I infer the current timezone in Elixir or Erlang?validate request input phoenix elixirExUnit - Running DB setup code once, before all testsWorking with datetime in ElixirConverting between Ecto.DateTime and DateTimePhoenix/Ecto - converting ISO string into utc_datetime primitive typeQuery has_many associations - Ecto, PhoenixFormat date with ElixirIs it possible to merge two separate ecto queries?

Avoiding estate tax by giving multiple gifts

What does "I’d sit this one out, Cap," imply or mean in the context?

A particular customize with green line and letters for subfloat

Opposite of a diet

Is HostGator storing my password in plaintext?

Is there a problem with hiding "forgot password" until it's needed?

How can a function with a hole (removable discontinuity) equal a function with no hole?

Did Dumbledore lie to Harry about how long he had James Potter's invisibility cloak when he was examining it? If so, why?

Where does the Z80 processor start executing from?

You cannot touch me, but I can touch you, who am I?

Anatomically Correct Strange Women In Ponds Distributing Swords

Is `x >> pure y` equivalent to `liftM (const y) x`

How did Arya survive the stabbing?

How do we know the LHC results are robust?

Sequence of Tenses: Translating the subjunctive

What is the intuitive meaning of having a linear relationship between the logs of two variables?

Two monoidal structures and copowering

Would a high gravity rocky planet be guaranteed to have an atmosphere?

Is this apparent Class Action settlement a spam message?

What can we do to stop prior company from asking us questions?

Integer addition + constant, is it a group?

How do I go from 300 unfinished/half written blog posts, to published posts?

What is the opposite of 'gravitas'?

How does buying out courses with grant money work?



How do you create a new DateTime since Ecto.DateTime was deprecated?


How can I get the current operating system name in Elixir?How do I infer the current timezone in Elixir or Erlang?validate request input phoenix elixirExUnit - Running DB setup code once, before all testsWorking with datetime in ElixirConverting between Ecto.DateTime and DateTimePhoenix/Ecto - converting ISO string into utc_datetime primitive typeQuery has_many associations - Ecto, PhoenixFormat date with ElixirIs it possible to merge two separate ecto queries?













1















I currently have a Date and a Time that I would really like to combine into a DateTime struct.



Prior to Ecto 3 you could do this with Ecto.DateTime.from_date_and_time but in the new documentation since the Ecto Types were deprecated I can't find an equivalent function.



The function currently looks like:



def add_datetime(date_as_string) do
(_, date = Date.from_iso8601(date)
end_time = #T[23:59:59]

datetime = datetime_add(Ecto.DateTime.from_date_and_time(date, end_time), -3, "day")
end


One of the constraints of this particular project is that I would like to avoid adding a third party library like Timex if at all possible but I am lost after looking at the current Elixir documentation.










share|improve this question


























    1















    I currently have a Date and a Time that I would really like to combine into a DateTime struct.



    Prior to Ecto 3 you could do this with Ecto.DateTime.from_date_and_time but in the new documentation since the Ecto Types were deprecated I can't find an equivalent function.



    The function currently looks like:



    def add_datetime(date_as_string) do
    (_, date = Date.from_iso8601(date)
    end_time = #T[23:59:59]

    datetime = datetime_add(Ecto.DateTime.from_date_and_time(date, end_time), -3, "day")
    end


    One of the constraints of this particular project is that I would like to avoid adding a third party library like Timex if at all possible but I am lost after looking at the current Elixir documentation.










    share|improve this question
























      1












      1








      1








      I currently have a Date and a Time that I would really like to combine into a DateTime struct.



      Prior to Ecto 3 you could do this with Ecto.DateTime.from_date_and_time but in the new documentation since the Ecto Types were deprecated I can't find an equivalent function.



      The function currently looks like:



      def add_datetime(date_as_string) do
      (_, date = Date.from_iso8601(date)
      end_time = #T[23:59:59]

      datetime = datetime_add(Ecto.DateTime.from_date_and_time(date, end_time), -3, "day")
      end


      One of the constraints of this particular project is that I would like to avoid adding a third party library like Timex if at all possible but I am lost after looking at the current Elixir documentation.










      share|improve this question














      I currently have a Date and a Time that I would really like to combine into a DateTime struct.



      Prior to Ecto 3 you could do this with Ecto.DateTime.from_date_and_time but in the new documentation since the Ecto Types were deprecated I can't find an equivalent function.



      The function currently looks like:



      def add_datetime(date_as_string) do
      (_, date = Date.from_iso8601(date)
      end_time = #T[23:59:59]

      datetime = datetime_add(Ecto.DateTime.from_date_and_time(date, end_time), -3, "day")
      end


      One of the constraints of this particular project is that I would like to avoid adding a third party library like Timex if at all possible but I am lost after looking at the current Elixir documentation.







      elixir phoenix






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 7 at 12:56









      SorvahSorvah

      1428




      1428






















          2 Answers
          2






          active

          oldest

          votes


















          2














          You can use DateTime.from_iso8601/2.



          datetime_iso8601 = "#Date.to_iso8601(date)T#Time.to_iso8601(time)+03:30"
          :ok, datetime, offset_from_utc = DateTime.from_iso8601(datetime_iso8601)


          Instead of +3:30 use your desired offset, or Z for UTC.






          share|improve this answer

























          • That worked superbly.Would you mind editing the answer to add the 'T' needed to make it a legal DateTime? so "#Date.to_iso8601(date)T#Time.to_iso8601(time)+03:30" then I can accept it.

            – Sorvah
            Mar 7 at 14:39











          • @Sorvah done :)

            – fhdhsni
            Mar 7 at 14:42



















          0














          For anyone finding this on Google you can also use a NaiveDateTime if you don't care about the timezone information:



          datetime= NaiveDateTime.new(date_struct, time_struct)
          |> DateTime.from_naive("Etc/UTC")





          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%2f55044333%2fhow-do-you-create-a-new-datetime-since-ecto-datetime-was-deprecated%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            You can use DateTime.from_iso8601/2.



            datetime_iso8601 = "#Date.to_iso8601(date)T#Time.to_iso8601(time)+03:30"
            :ok, datetime, offset_from_utc = DateTime.from_iso8601(datetime_iso8601)


            Instead of +3:30 use your desired offset, or Z for UTC.






            share|improve this answer

























            • That worked superbly.Would you mind editing the answer to add the 'T' needed to make it a legal DateTime? so "#Date.to_iso8601(date)T#Time.to_iso8601(time)+03:30" then I can accept it.

              – Sorvah
              Mar 7 at 14:39











            • @Sorvah done :)

              – fhdhsni
              Mar 7 at 14:42
















            2














            You can use DateTime.from_iso8601/2.



            datetime_iso8601 = "#Date.to_iso8601(date)T#Time.to_iso8601(time)+03:30"
            :ok, datetime, offset_from_utc = DateTime.from_iso8601(datetime_iso8601)


            Instead of +3:30 use your desired offset, or Z for UTC.






            share|improve this answer

























            • That worked superbly.Would you mind editing the answer to add the 'T' needed to make it a legal DateTime? so "#Date.to_iso8601(date)T#Time.to_iso8601(time)+03:30" then I can accept it.

              – Sorvah
              Mar 7 at 14:39











            • @Sorvah done :)

              – fhdhsni
              Mar 7 at 14:42














            2












            2








            2







            You can use DateTime.from_iso8601/2.



            datetime_iso8601 = "#Date.to_iso8601(date)T#Time.to_iso8601(time)+03:30"
            :ok, datetime, offset_from_utc = DateTime.from_iso8601(datetime_iso8601)


            Instead of +3:30 use your desired offset, or Z for UTC.






            share|improve this answer















            You can use DateTime.from_iso8601/2.



            datetime_iso8601 = "#Date.to_iso8601(date)T#Time.to_iso8601(time)+03:30"
            :ok, datetime, offset_from_utc = DateTime.from_iso8601(datetime_iso8601)


            Instead of +3:30 use your desired offset, or Z for UTC.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 7 at 14:41

























            answered Mar 7 at 14:19









            fhdhsnifhdhsni

            790716




            790716












            • That worked superbly.Would you mind editing the answer to add the 'T' needed to make it a legal DateTime? so "#Date.to_iso8601(date)T#Time.to_iso8601(time)+03:30" then I can accept it.

              – Sorvah
              Mar 7 at 14:39











            • @Sorvah done :)

              – fhdhsni
              Mar 7 at 14:42


















            • That worked superbly.Would you mind editing the answer to add the 'T' needed to make it a legal DateTime? so "#Date.to_iso8601(date)T#Time.to_iso8601(time)+03:30" then I can accept it.

              – Sorvah
              Mar 7 at 14:39











            • @Sorvah done :)

              – fhdhsni
              Mar 7 at 14:42

















            That worked superbly.Would you mind editing the answer to add the 'T' needed to make it a legal DateTime? so "#Date.to_iso8601(date)T#Time.to_iso8601(time)+03:30" then I can accept it.

            – Sorvah
            Mar 7 at 14:39





            That worked superbly.Would you mind editing the answer to add the 'T' needed to make it a legal DateTime? so "#Date.to_iso8601(date)T#Time.to_iso8601(time)+03:30" then I can accept it.

            – Sorvah
            Mar 7 at 14:39













            @Sorvah done :)

            – fhdhsni
            Mar 7 at 14:42






            @Sorvah done :)

            – fhdhsni
            Mar 7 at 14:42














            0














            For anyone finding this on Google you can also use a NaiveDateTime if you don't care about the timezone information:



            datetime= NaiveDateTime.new(date_struct, time_struct)
            |> DateTime.from_naive("Etc/UTC")





            share|improve this answer



























              0














              For anyone finding this on Google you can also use a NaiveDateTime if you don't care about the timezone information:



              datetime= NaiveDateTime.new(date_struct, time_struct)
              |> DateTime.from_naive("Etc/UTC")





              share|improve this answer

























                0












                0








                0







                For anyone finding this on Google you can also use a NaiveDateTime if you don't care about the timezone information:



                datetime= NaiveDateTime.new(date_struct, time_struct)
                |> DateTime.from_naive("Etc/UTC")





                share|improve this answer













                For anyone finding this on Google you can also use a NaiveDateTime if you don't care about the timezone information:



                datetime= NaiveDateTime.new(date_struct, time_struct)
                |> DateTime.from_naive("Etc/UTC")






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 7 at 15:26









                SorvahSorvah

                1428




                1428



























                    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.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55044333%2fhow-do-you-create-a-new-datetime-since-ecto-datetime-was-deprecated%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

                    Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

                    Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

                    Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved