title: How can i add more time (months) to an existing timestamp in mongo db using reactjs or js in general
body: <p>I am building a website and in a component, when the user clicks the respective button I need it to add 1/3/6/12 months to the current date in the database. I can make it update to a pre typed date, but I need it to add more months to that current date, and I couldn't find any way to do that from what I have searched.</p>
  <p>This is the code I need the function to happen in.</p>
  <pre><code>import React, { useContext } from &quot;react&quot;;
  import { useState } from &quot;react&quot;;
  import useFetch from &quot;../../hooks/useFetch&quot;;
  import Footer from &quot;../../components/Footer&quot;;
  import Navbar from &quot;../../components/Navbar&quot;;
  import Sidebar from &quot;../../components/Sidebar&quot;;
  import {
    ContractContainer,
    HeadingContainer,
    TypeH1,
    ActiveUntil,
    MonthlyWrapper,
    MonthlyContainer,
    MonthNumber,
    Price,
    Navbarback,
  } from &quot;./userinfoElements&quot;;
  import { AuthContext } from &quot;../../context/AuthContext&quot;;
  import moment from &quot;moment&quot;;
  import axios from &quot;axios&quot;;
  
  const Userinfo = () =&gt; {
    const [isOpen, setIsOpen] = useState(false);
  
    // set state to true ir false
    const toggle = () =&gt; {
      setIsOpen(!isOpen);
    };
  
    const { user } = useContext(AuthContext);
    const { data, loading } = useFetch(`/contracts/${user.contractType}`);
  
    const updateDate = async () =&gt; {
      axios.put(`/activedate/${user.namekey}`, {
        activeUntil: &quot;2026-08-30T22:00:00.000+00:00&quot;,
      });
    };
  
    const dateFormat = moment(user.activeUntil).format(&quot;DD/MMMM/yyyy&quot;);
  
    return (
      &lt;&gt;
        &lt;Sidebar isOpen={isOpen} toggle={toggle} /&gt;
        {/* navbar for smaller screens*/}
        &lt;Navbar toggle={toggle} /&gt;
        &lt;Navbarback /&gt; {/* filling for transparent bacground navbar*/}
        {loading ? (
          &quot;Loading components, please wait&quot;
        ) : (
          &lt;&gt;
            &lt;ContractContainer&gt;
              &lt;HeadingContainer&gt;
                &lt;TypeH1&gt;{data.contractType}&lt;/TypeH1&gt;
                &lt;ActiveUntil&gt;Subscription active until {dateFormat}&lt;/ActiveUntil&gt;
              &lt;/HeadingContainer&gt;
              &lt;MonthlyWrapper&gt;
                &lt;MonthlyContainer&gt;
                  &lt;MonthNumber&gt;1 Month&lt;/MonthNumber&gt;
                  &lt;Price onClick={updateDate}&gt;{data.month1Price}$&lt;/Price&gt;
                &lt;/MonthlyContainer&gt;
                &lt;MonthlyContainer&gt;
                  &lt;MonthNumber&gt;3 Month&lt;/MonthNumber&gt;
                  &lt;Price onClick={updateDate}&gt;{data.month3Price}$&lt;/Price&gt;
                &lt;/MonthlyContainer&gt;
                &lt;MonthlyContainer&gt;
                  &lt;MonthNumber&gt;6Month&lt;/MonthNumber&gt;
                  &lt;Price onClick={updateDate}&gt;{data.month6Price}$&lt;/Price&gt;
                &lt;/MonthlyContainer&gt;
                &lt;MonthlyContainer&gt;
                  &lt;MonthNumber&gt;12Month&lt;/MonthNumber&gt;
                  &lt;Price onClick={updateDate}&gt;{data.month12Price}$&lt;/Price&gt;
                &lt;/MonthlyContainer&gt;
              &lt;/MonthlyWrapper&gt;
            &lt;/ContractContainer&gt;
          &lt;/&gt;
        )}
        &lt;Footer /&gt;
      &lt;/&gt;
    );
  };
  
  export default Userinfo;
  </code></pre>
  <p>This is the part I am having problems with</p>
  <pre><code> const updateDate = async () =&gt; {
      axios.put(`/activedate/${user.namekey}`, {
        activeUntil: &quot;2026-08-30T22:00:00.000+00:00&quot;,
      });
    };
  </code></pre>
  <p>Also, if possible, is there any way I can make this <code>  const dateFormat = moment(user.activeUntil).format(&quot;DD/MMMM/yyyy&quot;);</code> get updated when the date changes? Currently, when the date changes, the user has to log out and log back in to get the new updated date.</p>
  <p>The mongoose schema I am using.</p>
  <pre><code>import mongoose from &quot;mongoose&quot;;
  const UserSchema = new mongoose.Schema({
    fName: { type: String },
    lName: { type: String },
    namekey: {
      type: String,
      required: true,
      unique: true,
    },
    password: {
      type: String,
      required: true,
    },
    contractType: {
      type: String,
    },
    activeUntil: {
      type: Date,
    },
  });
  
  export default mongoose.model(&quot;User&quot;, UserSchema);
  
  </code></pre>
  <p>Let me know if you need more information, I appreciate any answers.</p>