For a few days now, I have been attempting to save a timestamp from an API call to Postgres using my server-side C# code.
When attaching DateTime.Now()
to the data transfer object, everything seems to work fine. However, when trying to parse a datetime sent from the client, I receive a 400 error with
**0: "The input was not valid."**.
as my response.
Here is how my classes are structured:
TS:
export interface ArtistShows {
showDate: string;
venue: string;
id?: string;
bandsAlsoPlaying: Array<string>;
}
C#
public class ArtistShow
{
public Guid Id { get; set; }
public DateTime ShowDate { get; set; }
public string Venue { get; set; }
public string BandsAlsoPlaying { get; set; }
public virtual Artist Artist { get; set; }
}
Method that maps new form (with outputted Date) (TS)
private _mapNewShowForm(): ArtistShows {
let showDate = this.newShowForm.get(this.newShowFormEnum.DATE).value;
let convertedShowDate = new Date(showDate);
return {
bandsAlsoPlaying: [],
showDate: convertedShowDate.toISOString(),
venue: `${this.newShowForm.get(this.newShowFormEnum.VENUE).value}, ${this.newShowForm.get(this.newShowFormEnum.CITY).value}`
};
}
The date format from request is "2019-01-04T00:00:00.000Z" while the required format for storing in PG is "2018-12-29 20:23:22.667766" <-- Dates are stored in PG as timestamp without timezone
My main query is whether I should be sending my date to the backend in a specific format (I've heard it's ISO 8601)? Should there be any manipulation done to the Date on the client side? And how can I convert my JS date to a format that will correctly save in PG?
I am also utilizing Microsoft Entity Framework Core with Postgres (if that helps).