-3

I want to change the format of a date in vb.net so I can insert it in a MySQL table.

my code:

LblDateInc.Text = Date.Today

result: 10/18/2017

in mysql table the column date need to look like this: 2017/10/18

so how to change the format of the date in vb.net or in mysql thank you

user692942
  • 16,398
  • 7
  • 76
  • 175
sako
  • 93
  • 8
  • Is the database column a string or date type? – David Wilson Oct 18 '17 at 09:24
  • the database column a date type – sako Oct 18 '17 at 09:26
  • Also [this](https://stackoverflow.com/questions/3025361/c-sharp-datetime-to-yyyymmddhhmmss-format) – A Friend Oct 18 '17 at 09:29
  • Use `ToString("yourformatstring")`, it's in [the documentation](https://learn.microsoft.com/en-gb/dotnet/api/system.datetime.tostring?view=netframework-4.7.1#System_DateTime_ToString_System_String_). – user692942 Oct 18 '17 at 09:30
  • @AFriend it work thank you :) – sako Oct 18 '17 at 09:32
  • Possibel duplicate of [Convert Datetime Format in Vb.net](//stackoverflow.com/q/22397856) *(better dup target aimed at VB.Net, however, the syntax is not that different)*. – user692942 Oct 18 '17 at 12:04
  • Sidenote: If you need a sortable and non-locale dependent (always a good idea) format, use a standard format, i.e. ISO8601 `2017-10-18`. Every reasonable date/string conversion function/class/whatever should support this. – too honest for this site Oct 18 '17 at 12:12
  • *in mysql table the column date need to look like this: `2017/10/18`* Then you are doing it wrong. Dates do not have a format; strings do. Strings wont act like dates – Ňɏssa Pøngjǣrdenlarp Oct 18 '17 at 13:54

1 Answers1

-1

Use this

LiblDateInc.Text = DateTime.Now.ToString("yyyy/MM/dd")
Xyz
  • 5,955
  • 5
  • 40
  • 58
  • 1
    You seriously don't need to answer this, it isn't the first time someone has asked how to format a date in .Net. - [Format date in C#](//stackoverflow.com/a/2151752) – user692942 Oct 18 '17 at 09:31
  • Also `DateTime.Now` is not needed as the OP isn't interested in the time, so `DateTime.Today.ToString("yyy/MM/dd")` would work just as well. – user692942 Oct 18 '17 at 09:50