I can't get field to display an existing date from my database

Viewed 36

This is bugging me. In my application I am updating a datetime value. I am doing so by first splitting the datetime into seperate date and time fields, and then upon updating I tell the program to merge the date back into the datetime value again.

I can enter new values just fine. They get saved correctly.

The only problem I am facing is that I cannot get the existing seperated values to display in my fields. I want the users to be able to see what values they already have before changing them. I am allowed to display the full datetime value without any problems, but not the seperate values for date and time.

        <b-form-row>
          <b-col lg="6">
            <b-form-group :label="$t('Move in date')">
              <b-date-picker  v-model="tenancy.dateForMovingIn"/>
            </b-form-group>
          </b-col>
        </b-form-row>
        
        <script>
        export default { 
        data() {
      return {
        tenancy: {
          moveInDateTime: null,
          dateForMovingIn: null,
        }
    },
    methods: {
      show(tenancy) {

        tenancy = JSON.parse(JSON.stringify(tenancy));

        tenancy.moveInDateTime = tenancy.moveInDateTime ? new Date(tenancy.moveInDateTime) : tenancy.moveInDateTime;
        tenancy.dateForMovingIn = moment(this.tenancy.moveInDateTime).format('YYYY-MM-DD')
        tenancy.timeForMovingIn = moment(this.tenancy.moveInDateTime).format('HH:mm')

        this.tenancy = tenancy
      },
 
      submit() {
        this.tenancy.moveInDateTime  = moment(this.tenancy.dateForMovingIn + ' ' + this.tenancy.timeForMovingIn, 'YYYY-MM-DD HH:mm')
        this.tenancy.moveOutDateTime = moment(this.tenancy.dateForMovingOut + ' ' + this.tenancy.timeForMovingOut, 'YYYY-MM-DD HH:mm')
        }
      }
    }
        </script>

0 Answers
Related