Android Question Days of the week

Discussion in 'Android Questions' started by rogel a. tolentino, Apr 30, 2019.

  1. rogel a. tolentino

    rogel a. tolentino Member Licensed User

    To determine the day of the week of a current date is Datetime.getDayOfWeek(DateTime.now)
    how about not a current date
    example April 27, 2019
     
  2. DonManfred

    DonManfred Expert Licensed User

    Code:
    Dim SomeTime As Long
        SomeTime = 
    DateTime.DateParse("04/27/2019")
    determine the day from SomeTime
     
  3. rogel a. tolentino

    rogel a. tolentino Member Licensed User

    I tried your sample code but still an error?
    What is the expected output of that?
     
  4. DonManfred

    DonManfred Expert Licensed User

    WHICH ERROR????????

    Hard to help you with this less info you provide!
     
  5. rogel a. tolentino

    rogel a. tolentino Member Licensed User

    im SomeTime As Long
    when passing here
    SomeTime = DateTime.DateParse("04/27/2019")
    the android phone message is MRS keeps stopping
     
  6. DonManfred

    DonManfred Expert Licensed User

    NEVER. Check the log. There is NO Crash without the error in the log in Android
     
  7. DonManfred

    DonManfred Expert Licensed User

    It is working fine her

    Code:
    Dim SomeTime As Long
        SomeTime = 
    DateTime.DateParse("04/27/2019")
        
    Log(SomeTime)
     

    Attached Files:

  8. picenainformatica

    picenainformatica Active Member Licensed User

    Try with "27/04/2019"
     
  9. DonManfred

    DonManfred Expert Licensed User

    the code is the one from the onlinehelp
    [​IMG]
    Look at the Date. MONTH/DAY/YEAR
     
  10. RWK

    RWK Member Licensed User

    Code:
    Dim WeekDay    As Int
        
    Dim WeekDayLong() As String = Array As String("ErelsDay","Sunday""Monday""Tuesday""Wednesday""Thursday""Friday""Saturday")
        WeekDay = 
    DateTime.GetDayOfWeek(DateTime.DateParse("04/28/2019"))
        
    Log (WeekDayLong(WeekDay))
    Greetings
    Rainer
     
    mangojack and DonManfred like this.
  11. Erel

    Erel Administrator Staff Member Licensed User

    Code:
    Log(DateUtils.GetDayOfWeekName(DateTime.DateParse("04/28/2019")))
     
  12. ANGELINE ROMAN

    ANGELINE ROMAN Member Licensed User

    I already understand dateparse
    for example a given date stored in a string variable
    say date1="04/27/2019"
    when you add 3 days the new date is "04/30/2019"
    can somebody help me a b4a code that will display the original date and the new date
    both date in mm/dd/yyyy format
    Thanks
     
  13. emexes

    emexes Well-Known Member Licensed User

    This example:
    Code:
    Dim Date1 As Long    'milliseconds since year dot
    Dim Date2 As Long

    DateTime.DateFormat = "MM/dd/yyyy"    'is default, but best to be sure

    Date1 = 
    DateTime.DateParse("04/27/2019")
    Date2 = 
    DateTime.Add(Date1, 003)    'add 3 days

    Log("First Date = " & DateTime.Date(Date1))
    Log("Second Date = " & DateTime.Date(Date2))
    generates this log (but you could just as easily put the strings to a label as to the log):
    Code:
    First Date = 04/27/2019
    Second Date = 
    04/30/2019
    edit: removed date-time arithmetic alternative, because it gets messy with daylight savings / summer time adjustments
     
    Last edited: May 1, 2019
    rogel a. tolentino likes this.
  14. emexes

    emexes Well-Known Member Licensed User

    reverting back to the original weekday question, another way of doing it might be:
    Code:
    Dim SaveDateFormat As String = DateTime.DateFormat

    DateTime.DateFormat = "yyyy-MM-dd"
    Dim DateOfInterest As Long = DateTime.DateParse("2019-04-27")

    DateTime.DateFormat = "EEEE"
    Log("as weekday = " & DateTime.Date(DateOfInterest))

    DateTime.DateFormat = "EEEE MM/dd/yy"
    Log("as weekday and date = " & DateTime.Date(DateOfInterest))

    DateTime.DateFormat = "EEE MM/dd/yy"
    Log("as short weekday and date = " & DateTime.Date(DateOfInterest))

    DateTime.DateFormat = SaveDateFormat    'restore to original format
    Log("as original format = " & DateTime.Date(DateOfInterest))
    generates results:
    Code:
    as weekday = Sunday
    as weekday and date = Sunday 04/27/19
    as short weekday and date = Sun 04/27/19
    as original format = 04/27/2019
     
    rogel a. tolentino likes this.
  15. Erel

    Erel Administrator Staff Member Licensed User

    This is a mistake. Date and time arithmetics do not work.

    Watch the date and time video tutorial for more information: https://www.b4x.com/etp.html

    Use DateUtils.AddPeriod instead.
     
  16. emexes

    emexes Well-Known Member Licensed User

    That's a bit harsh :)

    Although I'm coming at it from a physics-time point of view, but you're right that from a clock-time point of view, I should have added a caveat that things will go a bit awry twice a year when daylight savings/summer time kicks in or out (although curiously, leap days are accounted for but leap seconds are not - what's that about?!?!)

    Given that the original question was about whole days and regardless of their length, I've rectified my post above.
    I did watch this, and it was great - I hadn't encountered that one-hour-is-three-hours time zone trap before, but as soon as you demonstrated it, I thought: man, I bet you must have explained that a few hundred times, no wonder you didn't hold back on declaring my arithmetic to be a mistake ;-)

    I assume DateTime.Add is still ok to use.
     
  17. Erel

    Erel Administrator Staff Member Licensed User

    Everything you wrote is correct. Using DateUtils.AddPeriod or DateTime.Add is simple enough to just suggest using these methods.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice