❔ Exporting data in c# winforms button goes wrong
Im having a problem exporting some data from my dgv, heres my code:
tha's c# code to export all data visible in the datagridview, my date is like 10-05-2025 but sometimes its exporting with "/" instead of "-" and its changing the date with the month, im from Portugal and i cant figure this out i tried a lot of different things and nothing happend, sometimes some dates come with that , and the others correctly( i also search in the DB if i was inserting the data wrong but im not).
Would love some help thanks
https://pastebin.com/Wy0W9kD9
Pastebin
Text.txt - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
3 Replies
I assume, you are exporting an image and then, all sorts of other data in this code block here?
https://www.c-sharpcorner.com/blogs/date-and-time-format-in-c-sharp-programming1
here you got a little cheatsheet how you can create different datetime formats following ISO standards using .net
DateTime
objects by calling ToString()
on them.
I suggest you store the data as DateTime objects in your app and then use the suggested approach to create your desired datetime format string for UI and excel
you can also choose a seperator yourself this way, either /
or -
which you mentioned
for the other direction (from standardized datetime string to DateTime c# object) you can use DateTime.TryParse()
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.