Android Question Trouble Setting Date

LQQKIN

New Member
Licensed User
Longtime User
Hello, I am having difficulties setting a time for my alarm to go off. I can get a set date and time, but it's not in the correct format. To do this I need to convert everything to an integer and plug it into a separate syntax. However, I'm having trouble grabbing numbers from a string. This is my code:

B4X:
Sub whlTime_Closed(Canceld As Boolean, Time As String)
    If Canceld = False Then
        lblDateTime.Text = lblDateTime.Text & " " & Time
        'STARTTIMEPORTD1 = DateUtils.SetDateAndTime(newyear, newmonth, newday, newhour, newmin, 0)
        '(starttimeportD1 being the alarm that needs to be set)
    End If
End Sub

An example is setting the date. I can pull up a date in the format of "08/12/2013 15:06" but I need it to be cut into chunks [to plug into starttimeportD1]. How can I get it so
newyear = 2013,
newmonth= 08,
newday = 12
newhour = 15
newmin = 06?

Thanks for any help!
 

Mahares

Expert
Licensed User
Longtime User
I think this is what you are looking for:
B4X:
DateTime.DateFormat="MM/dd/yyyy HH:mm"
Dim strDate As String= "08/12/2013 15:06"
Dim lngDate As Long=DateTime.DateParse(strDate)
Dim newyear As Int=DateTime.GetYear(lngDate)
Dim newmonth As Int=DateTime.GetMonth(lngDate)
Dim newday As Int=DateTime.GetDayOfMonth(lngDate)
Dim newhour As Int=DateTime.GetHour(lngDate)
Dim newmin As Int=DateTime.GetMinute(lngDate)
Msgbox( newyear & "  " & newmonth & "  " & newday & "  " & newhour & "  " & newmin,"") 'returns 2013  8  12  15  6
 
Upvote 0
Top