I have created a .html and .ts file (code as below), I have used primeng component to set the calendar and the values I'm getting the data from the calendar is {Sat Mar 16 2021 10:58:55 GMT+0530 (India Standard Time)} but I need to pass the datetime values in database via formbuilder.
Question: How do I pass/send calendar date and time values to database to StartDate?
I have also used the datepipe to transform the given data to desired date and time format.
.html file
<div class="col-md-6">
<label class="form-label">Start Date</label>
<div class="form-control-wrap">
<p-calendar [(ngModel)]="date_val" formControlName="StartDate" name="StartDate" [showTime]="true" hourFormat="24" inputId="time" dateFormat="yy-mm-dd"></p-calendar>
</div>
</div>
I'm getting
import { DatePipe } from '@angular/common';
export class CreateEventComponent implements OnInit {
date_val!: Date;
constructor(private formBuilder: FormBuilder,
private auth: AuthService,
private route: Router) {
this.form = this.formBuilder.group({
});
}
ngOnInit(): void {
var start_date =this.datepipe.transform(this.date_val, 'yyyy-MM-dd');
this.currentUser = JSON.parse(localStorage.getItem('current_user') || '{}');
this.createEventForm = this.formBuilder.group({
EventName: [''],
EventType: [''],
HostUserEmail: this.currentUser.email,
StartDate: this.start_date,
});
}