Forum » Programiranje » [vb.net] parsing string v date
[vb.net] parsing string v date
Samsung06 ::
Hej
Rad bi pretvoril nek string v date.
Primeri:
1)
Dim _test_1 As String = "29/2/2000" 'NE DELA
Dim dtDate1 As Date = Date.ParseExact(_test_1, "dd/MM/yyyy", Nothing).ToString()
2)
Dim _test_2 As String = "29/02/2000" 'NE DELA
Dim dtDate2 As Date = Date.ParseExact(_test_2, "dd/MM/yyyy", Nothing).ToString()
3)
Dim _test_3 As String = "29/2/2000" 'NE DELA
Dim dtDate3 As Date = Date.ParseExact(_test_3, "dd/M/yyyy", Nothing).ToString()
4)
Dim _test_4 As String = "29-2-2000" 'NE DELA
Dim dtDate4 As Date = Date.ParseExact(_test_4, "dd-MM-yyyy", Nothing).ToString()
5)
Dim _test_5 As String = "29-02-2000" 'DELA
Dim dtDate5 As Date = Date.ParseExact(_test_5, "dd-MM-yyyy", Nothing).ToString()
6)
Dim _test_6 As String = "29-2-2000" 'DELA
Dim dtDate6 As Date = Date.ParseExact(_test_6, "dd-M-yyyy", Nothing).ToString()
Ne vem, kako bi naredil, da bi mi delal 1) primer?
Rad bi pretvoril nek string v date.
Primeri:
1)
Dim _test_1 As String = "29/2/2000" 'NE DELA
Dim dtDate1 As Date = Date.ParseExact(_test_1, "dd/MM/yyyy", Nothing).ToString()
2)
Dim _test_2 As String = "29/02/2000" 'NE DELA
Dim dtDate2 As Date = Date.ParseExact(_test_2, "dd/MM/yyyy", Nothing).ToString()
3)
Dim _test_3 As String = "29/2/2000" 'NE DELA
Dim dtDate3 As Date = Date.ParseExact(_test_3, "dd/M/yyyy", Nothing).ToString()
4)
Dim _test_4 As String = "29-2-2000" 'NE DELA
Dim dtDate4 As Date = Date.ParseExact(_test_4, "dd-MM-yyyy", Nothing).ToString()
5)
Dim _test_5 As String = "29-02-2000" 'DELA
Dim dtDate5 As Date = Date.ParseExact(_test_5, "dd-MM-yyyy", Nothing).ToString()
6)
Dim _test_6 As String = "29-2-2000" 'DELA
Dim dtDate6 As Date = Date.ParseExact(_test_6, "dd-M-yyyy", Nothing).ToString()
Ne vem, kako bi naredil, da bi mi delal 1) primer?
dolenc ::
Ne vem točno za kak primer gre, ponavadi rabiš ravno obratno, imaš polje, ki ima format date, pa potem preurediš string, da ga lahko naprej uporabljaš v querijih.
Recimo če bi želel tak izpis #yyy/mmm/dd#
datum = "#" & Year(xpolje) & "/" & Month(xpolje) & "/" & Day(xpolje) & "#"
Če bi rad pa iz stringa naredil datum pa enostavno uporabi format v kodi.
Format (#17/04/2004#, "Short Date") would return '17/04/2004'
Format (#17/04/2004#, "Long Date") would return 'April 17, 2004'
Format (#17/04/2004#, "yyyy/mm/dd") would return '2004/04/17'
Recimo primerček :)
Seveda date je samo oblika(ni spremenljivka), če uporabiš pravilno formatiran string bo program vedel zakaj gre.
Recimo če bi želel tak izpis #yyy/mmm/dd#
datum = "#" & Year(xpolje) & "/" & Month(xpolje) & "/" & Day(xpolje) & "#"
Če bi rad pa iz stringa naredil datum pa enostavno uporabi format v kodi.
Format (#17/04/2004#, "Short Date") would return '17/04/2004'
Format (#17/04/2004#, "Long Date") would return 'April 17, 2004'
Format (#17/04/2004#, "yyyy/mm/dd") would return '2004/04/17'
Recimo primerček :)
Seveda date je samo oblika(ni spremenljivka), če uporabiš pravilno formatiran string bo program vedel zakaj gre.
Vredno ogleda ...
Tema | Ogledi | Zadnje sporočilo | |
---|---|---|---|
Tema | Ogledi | Zadnje sporočilo | |
» | [VB] date regexOddelek: Programiranje | 836 (755) | korenje3 |
» | C# težavaOddelek: Programiranje | 3702 (2548) | mladec |
» | [VB] datagridviewOddelek: Programiranje | 1933 (1316) | korenje3 |
» | [java] datumiOddelek: Programiranje | 1768 (1641) | l0g1t3ch |
» | sql, asp in datumiOddelek: Programiranje | 1088 (892) | plizzzzzz |