Hey everybody,
I want get min and max of my date column “[RÇU]Date de réception (Date)” of my datatable ‘dt’.
Can you help me ?
Thank !
Hey everybody,
I want get min and max of my date column “[RÇU]Date de réception (Date)” of my datatable ‘dt’.
Can you help me ?
Thank !
Hi,
Can you try the following expression?
Max
dt.AsEnumerable.Max(Function(r) DateTime.Parse(r(0).ToString))
Min
dt.AsEnumerable.MIn(Function(r) DateTime.Parse(r(0).ToString))
The above returns DateTime type. If you need string please add .ToString
Regards,
Thank man, but where i specify my column name ?
Hi,
Sorry, the following will work
dt.AsEnumerable.Max(Function(r) DateTime.Parse(r("[RÇU]Date de réception (Date)").ToString))
dt.AsEnumerable.Min(Function(r) DateTime.Parse(r("[RÇU]Date de réception (Date)").ToString))
Regards,
Thanks again but i have error message.
‘String was not recognized as a valid DateTime.’
Hi,
Is there any blank cell or non-datetime string in the column?
If so, the following will work. Can you try this?
dt.AsEnumerable.Where(Function(r) DateTime.TryParse(r("[RÇU]Date de réception (Date)").ToString,New DateTime)).Max(Function(r) DateTime.Parse(r("[RÇU]Date de réception (Date)").ToString))
Or if the above expression doesn’t return expected result and your datetime format is not dd-MM-yyyy style etc, we need to modify the above expression.
Regards,
You are the best, he work. But i need change datetime format to dd-MM-yyyy
Hi,
Can you add .ToString("dd-MM-yyyy")
as the following?
dt.AsEnumerable.Where(Function(r) DateTime.TryParse(r("[RÇU]Date de réception (Date)").ToString,New DateTime)).Max(Function(r) DateTime.Parse(r("[RÇU]Date de réception (Date)").ToString)).ToString("dd-MM-yyyy")
Regards,
Checkout if more assistance on analysing parsing validation issues is needed:
Perfect, but this expression return the min (‘12/04/2022’) when i should have ‘27/04/2022’
i try change Max → Min and is same
Hi,
it seems dd/MM/yyyy format. Can you try the following?
dt.AsEnumerable.Where(Function(r) DateTime.TryParseExact(r("[RÇU]Date de réception (Date)").ToString,"d/M/yyyy",System.Globalization.CultureInfo.InvariantCulture,DateTimestyles.None,New DateTime)).Max(Function(r) DateTime.ParseExact(r("[RÇU]Date de réception (Date)").ToString,"d/M/yyyy",System.Globalization.CultureInfo.InvariantCulture,DateTimestyles.None)).ToString("dd-MM-yyyy")
dt.AsEnumerable.Where(Function(r) DateTime.TryParseExact(r("[RÇU]Date de réception (Date)").ToString,"d/M/yyyy",System.Globalization.CultureInfo.InvariantCulture,DateTimestyles.None,New DateTime)).Min(Function(r) DateTime.ParseExact(r("[RÇU]Date de réception (Date)").ToString,"d/M/yyyy",System.Globalization.CultureInfo.InvariantCulture,DateTimestyles.None)).ToString("dd-MM-yyyy")
Regards,
DateTimestyles is not declared
import System.Globalization
Hi,
Can you try @ppr 's way or the following?
dt.AsEnumerable.Where(Function(r) DateTime.TryParseExact(r("[RÇU]Date de réception (Date)").ToString,"d/M/yyyy",System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimestyles.None,New DateTime)).Max(Function(r) DateTime.ParseExact(r("[RÇU]Date de réception (Date)").ToString,"d/M/yyyy",System.Globalization.CultureInfo.InvariantCulture,System.Globalization.DateTimestyles.None))
Regards,
thank you so much !
thank you so much !!!
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.