cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mrstian89
Helper V
Helper V

Date format issues on different devices

Hi!
I have recently created a calendar app at my company.

It works flawlessly on a computer, but when opening the same app on my iPhone, there is trouble due to the DateFormat.

 

1. When I open the calendar screen i use the following code to set:

- First date of this month

- First day of this months calendar view (for October it is 26. September, since we use a Monday - Sunday week).

- Last day of this months calendar view (for October it is 06. Sovember)

 

Set(varMonth,DateValue(Month(Today()) & "/" & "1" & "/" & Year(Today())));

Set(varFirstDayView, DateAdd(varMonth, - Weekday(varMonth,Monday), Days));

Set(varFirstDayNextMonth, DateAdd(DateAdd(varMonth, 1, Months), 7 - Weekday(DateAdd(varMonth, 1, Months),Monday), Days));

 

 

As I have said, this works fine on my computer. But on my phone the date format automatically is set to dd.mm.yyyy, making all the formulas to fail.

 

I have tried several methods:

- DateValue(xx,"different language codes")

- Formatting the dates in the code, but I have not yet found a way.

 

Is there a simple way to make thise code work on any device? Cheers! 

 

The code for going to the next month:

Set(varMonth,DateAdd(varMonth,1, Months));

Previous month:

Set(varMonth,DateAdd(varMonth,-1, Months));

 

1 ACCEPTED SOLUTION

Accepted Solutions
mrstian89
Helper V
Helper V

Solved it.

Set(varMonth,DateValue(Month(Today()) & "/" & "1" & "/" & Year(Today()),"en"));

Set(varFirstDayView, DateValue(DateAdd(varMonth, - Weekday(varMonth,Monday), Days)));

Set(varFirstDayNextMonth, DateValue(
                            Text(
                                DateAdd(
                                    DateAdd(DateValue(Text(varMonth,"mm/dd/yyyy"),"en"), 1, Months),
                                    7 - Weekday(DateAdd(DateValue(Text(varMonth,"mm/dd/yyyy"),"en"), 1, Months),Monday),
                                Days),
                            "mm/dd/yyyy"),
                            "en"));



//////////////////

Set(varMonth,DateAdd(DateValue(Text(varMonth,"mm/dd/yyyy"),"en"),1, Months));

 Now it work both on PC and phone.

View solution in original post

1 REPLY 1
mrstian89
Helper V
Helper V

Solved it.

Set(varMonth,DateValue(Month(Today()) & "/" & "1" & "/" & Year(Today()),"en"));

Set(varFirstDayView, DateValue(DateAdd(varMonth, - Weekday(varMonth,Monday), Days)));

Set(varFirstDayNextMonth, DateValue(
                            Text(
                                DateAdd(
                                    DateAdd(DateValue(Text(varMonth,"mm/dd/yyyy"),"en"), 1, Months),
                                    7 - Weekday(DateAdd(DateValue(Text(varMonth,"mm/dd/yyyy"),"en"), 1, Months),Monday),
                                Days),
                            "mm/dd/yyyy"),
                            "en"));



//////////////////

Set(varMonth,DateAdd(DateValue(Text(varMonth,"mm/dd/yyyy"),"en"),1, Months));

 Now it work both on PC and phone.

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (2,161)