New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Datetime format #39
Comments
I will give you an example shortly here. Sorry for the slow reply. Date formatting is probably a common enough thing to warrant a DateFormat property as a part of the configuration. I haven't got around to doing that yet. |
What is wrong with what you were doing? That seemed to work fine for me. |
Problem is this seems to work on my development machine but once i deploy it to the production server. It gives me errors |
What are the errors you're seeing? |
I'm closing this since I haven't heard back in 2 months. |
Do you have a config level / global type converter option or it needs to be attached on specific properties via type maps? Ex. When exporting, i want all dates written as yyyy-MM-dd. Is there a way to do that outside of on a per property basis in individual type maps? |
Yes. var options = new TypeConverterOptions
{
Format = "yyy-MM-dd",
};
CsvHelper.TypeConversion.TypeConverterOptionsFactory.AddOptions<DateTime>(options); |
Actually... that looks to be global. So if in a process i'm reading and writing with differing standard formats, it's an issue right? I was hoping for something via the CsvConfiguration object? Since that's the object being passed to readers and writers. Is there a way to set that per reader / writer? |
Not right now. It's planned though. #318 |
Took me hours to find this, could you put a TypeConverterOptionsFactory example on your page? |
CsvHelper.TypeConversion.TypeConverterOptionsFactory unable to find this class, using version 2.2.0 |
It was renamed to |
How does one control the datetime format of a property. I have tried the following
[TypeConverter(typeof(CustomDateTimeTypeConverter))]
public DateTime? Dob
{
get { return _dob; }
set { _dob = value; }
}
public class CustomDateTimeTypeConverter : DateTimeConverter
{
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
{
if (destinationType == typeof(string))
{
return ((DateTime)value).ToString("dd-MM-yyyy");
}
return base.ConvertTo(context, CultureInfo.InvariantCulture, value, destinationType);
}
}
The text was updated successfully, but these errors were encountered: