Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4839

Change DateTime output or Format the order

$
0
0

I am using Blazor and I have an this input date field.

<div class="input-group"><InputDate name="To Date" class="form-control rounded-2" @bind-Value="auditForm.toDate" @bind-Value:format="yyyy/MM/dd" TValue="DateTime" /></div>

And I am parsing the value to the parent via parameter where I am using the values to display a certain form.

This is the code block on the parent.

    // Method to handle form submission from child component    private async Task HandleFilterSubmitted(AuditForm auditForm)    {        // Update search parameters        searchType = auditForm.searchType;        searchCriteria = auditForm.searchCriteria;        fromDate = auditForm.fromDate;        toDate = auditForm.toDate;        // Reload audit trail with updated parameters        await LoadAuditTrail();        // Log the values of the AuditForm object        _logger.LogInformation("Search Type: {SearchType}, Search Criteria: {SearchCriteria}, From Date: {FromDate}, To Date: {ToDate}",        auditForm.searchType, auditForm.searchCriteria, auditForm.fromDate, auditForm.toDate);    }

I would like the DateTime format to be parsed in this specific order: yyyy/MM/dd not the default dd/MM/yyyy

This is my console output of how it should not look like:enter image description here

I have tried using the bind-Value:format methodI tried converting it to a string and it will not work because my server is expecting a DateTime object not a string.

I have read on plenty articles but they are all converting to string which is what I do not want to do.

I want to change the formatting from dd/MM/yyyy to yyyy/MM/dd when the data is being assigned here:

        // Update search parameters        searchType = auditForm.searchType;        searchCriteria = auditForm.searchCriteria;        fromDate = auditForm.fromDate; //HERE        toDate = auditForm.toDate; //HERE

Viewing all articles
Browse latest Browse all 4839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>