[HELP] How to make a countdown??

rickrack

Member
Licensed User
Longtime User
Hello, I'm sorry to bore you with all these questions, but there's one other thing I can't solve by myself...
I would like to make a countdown for AS Roma (italian team) football matches as I did in my website (is it permitted to link it?)..
This is my plan:
1- Get date and time of next match from a txt file on my server (just did it)
2- "Subtract" the now Time and Date from the date I downloaded from the server
3- Show the numbers in the labels (should not be a problem, i'll try by myself this one)

I have problems by making a "dateparse" with my downloaded string... do you have any advise for me?
I'm sorry for some grammar errors you encountered in this text

Thanks in advance,
Riccardo
 

rickrack

Member
Licensed User
Longtime User
Thank you for reply, Erel

This is the website, you can find the countdown widget just after the articles slider:As Roma Streaming

Now I changed the code and tried other functions so I haven't details about the DataParse problem.

Do you have any ideas for this countdown?
 
Upvote 0

rickrack

Member
Licensed User
Longtime User
I have problems by subtracting the time.. I would like to subtract from the downloaded date years, months, days, hours, minutes and seconds of now and transform them as seconds, so i could "split the time" and assign it to the labels. This is a screenshot of asromastreaming.net countdown: Screenshot
I searched and tried one of the function I found in the forum but just the minutes have been subtracted
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Subtract DateTime.Now from the parsed date and then use a method such as:
B4X:
Sub ConvertTicksToTimeString(t As Long) As String
    Dim days, hours, minutes, seconds As Int
    days = t / DateTime.TicksPerDay
    hours = (t Mod DateTime.TicksPerDay) / DateTime.TicksPerHour
    minutes = (t Mod DateTime.TicksPerHour) / DateTime.TicksPerMinute
    seconds = (t Mod DateTime.TicksPerMinute) / DateTime.TicksPerSecond
    Return days & " days, " & NumberFormat(hours, 2, 0) & " hours, " _
        & NumberFormat(minutes, 2, 0) & " minutes and " & NumberFormat(seconds, 2, 0) & " seconds"
End Sub
 
Upvote 0

rickrack

Member
Licensed User
Longtime User
Thank you, but the problem for me is to subtract datetime.now! I can't find how to do it...
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use this code:
B4X:
Dim dateString As String = "21/10/2012, 20:45"
   Dim date, time As Long
   Dim parts() As String = Regex.Split(", ", dateString)
   DateTime.DateFormat = "dd/MM/yyyy"
   DateTime.TimeFormat = "HH:mm"
   date = DateTime.DateParse(parts(0))
   time = DateTime.TimeParse(parts(1)) - DateTime.DateParse(DateTime.Date(DateTime.Now)) 'Remove the today date component
   Log(ConvertTicksToTimeString(date + time - DateTime.Now))
   
Sub ConvertTicksToTimeString(t As Long) As String
    Dim days, hours, minutes, seconds As Int
    days = t / DateTime.TicksPerDay
    hours = (t Mod DateTime.TicksPerDay) / DateTime.TicksPerHour
    minutes = (t Mod DateTime.TicksPerHour) / DateTime.TicksPerMinute
    seconds = (t Mod DateTime.TicksPerMinute) / DateTime.TicksPerSecond
    Return days & " days, " & NumberFormat(hours, 2, 0) & " hours, " _
        & NumberFormat(minutes, 2, 0) & " minutes and " & NumberFormat(seconds, 2, 0) & " seconds"
End Sub

It assumes that the target time zone is the same as the device time zone.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…