VB.NET: Extract day, month or year from the Listbox

toytoy
01-24-2005, 12:03 AM
Say i have these dates:

12-2-05......can
12-12-05....can
12-13-05....cannot
12-22-05....cannot

Refer to the above dates, why the below XML tag could not work well with days above "12"... when i send to server..
I could only send 1,2,3,4,5,....up to 12 only.

"<" & "Date" & " " & "day=" & """" & Convert.ToDateTime(lst.SelectedItem.ToString).Date.Day & """" & " "
& "month=" & """" & Convert.ToDateTime(lst.SelectedItem.ToString).Date.Month & """" & " " & "year=" & """"
& Convert.ToDateTime(lst.SelectedItem.ToString).Date.Year & """" & " >" & _
</" & "Date" & ">" & _

The error message is:

Additional information: String was not recognized as a valid DateTime.

Does anyone have better solution to solve it....

Thanks

Iceplug
01-24-2005, 06:55 AM
Does it work correctly? As in the .Month returned from all of them is 12?
Maybe it's expecting the date in dd-MM-yy format.

toytoy
01-25-2005, 09:51 PM
I find the problem is on the Format of the D/MM/YYYY...

After i change the date format, it could work...

Is there any way to format the date so that the program could works well in all

computers without having to worry about whether the computer have set to the

required date format.....

Thanks

Iceplug
01-26-2005, 08:21 AM
How are the dates getting into the listbox in the first place?

Don't forget that there is also the DateTime.Parse() function that converts a date string into a datetime value.
:)

toytoy
01-26-2005, 07:38 PM
Say i have these XML tag

<book published="New York">
<date day="12" month="1" year="2005" />
</book>

How do i exactly format the date since i am getting three different attributes (day, month and year) from the server......

Say i want the format to be "DD/MM/YYYY"...

I want the format date to be displayed in the listbox...

Does anyone have any idea to combined all three attributes and format instead of format directly the date as a whole....

Thanks

sgt_pinky
01-26-2005, 09:00 PM
Do you absolutely need the day, etc, separate?

eg:


<book published="New York">
<date value="12/01/2005"/>
</book>


Then you could just rip it straight out, and parse it into a date variable, using the culture that you want. For example, say you have the date 8th of September, 2005. In british cultures, this would be written 8/9/2005, but in the US, 9/8/2005. If you are given the british version, 8/9/2005, then do this to parse the date correctly, and end up with a date variable in the US culture format:


Dim sDate As String = "8/9/2005" 'British - 8th Sep 2005
Dim CI As New Globalization.CultureInfo("en-AU")
Dim dd As Date = Date.Parse(sDate, CI)
MessageBox.Show("Day: " & dd.Day & ", Month: " & dd.Month & ", Year: " & dd.Year)

toytoy
01-26-2005, 10:46 PM
yeah...

i need it separate because i get separate dates from the server...

I am not sure how to combine three different attributes and go through the formating of dates...

sgt_pinky
01-27-2005, 03:20 PM
I'm not really sure what you mean, you will have to explain yourself better.


Dim sDay as String = "8"
Dim sMonth as String = "10"
Dim sYear as String = "2005"

Dim dDate as Date = Date.Parse(sMonth & "/" & sDay & "/" & sYear)
MessageBox.Show(dDate.ToString("d MMMM yyyy"))


Output is: "8 October 2005"

Is this what you mean?

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum