Date Format in Syncfusion® Daterangepicker Component
19 Jun 20253 minutes to read
Date format is a way of representing the date value in different string format in textbox.
By default the DateRangePicker’s format is based on the culture. You can also set the own custom format by using the format property.
NOTE
Once the date format property has been defined, it will be common to all the cultures.
To know more about the date format standards, refer to the Internationalization Date Format
section.
The following example demonstrates the DateRangePicker with the custom format (dd/MMM/yy hh:mm a
).
@Html.EJS().DateRangePicker("Rangepicker").Format("dd/MMM/yy hh:mm a").StartDate(ViewBag.startDate).EndDate(ViewBag.endDate).Render()
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace EJ2CoreSampleBrowser.Controllers
{
public class HomeController : Controller
{
public ActionResult DateRange()
{
ViewBag.startDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 20);
ViewBag.endDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month + 1, 25);
return View();
}
}
}
Input formats
The inputFormats
property in the DateRangePicker control allows users to enter dates in various formats, providing flexibility in date entry. This property accepts an array of predefined formats that the control recognizes, enabling users to input dates in different ways while ensuring they are parsed correctly.
When the user types the date in any of the specified input formats, it will be automatically converted to the display format after pressing Enter, the Tab key, or when the input loses focus. This enhances the user experience by allowing intuitive data entry through various custom input formats.
The following example demonstrates the DateRangePicker with multiple input formats.
@Html.EJS().DateRangePicker("Rangepicker").Format("dd/MMM/yy hh:mm a").StartDate(ViewBag.startDate).EndDate(ViewBag.endDate).InputFormats(new string[] { "dd/MM/yyyy", "yyyyMMdd" }).Render()
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
namespace EJ2CoreSampleBrowser.Controllers
{
public class HomeController : Controller
{
public ActionResult DateRange()
{
ViewBag.startDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 20);
ViewBag.endDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month + 1, 25);
return View();
}
}
}