cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
paguirre
Helper I
Helper I

Sending Date and Time to SharePoint Column Type Date and Time

New to PowerApps. I'm a high school teacher not a developer. This is my first question to this community. Thanks in advance.

I have a DateAndTime Input in a form. I have a button to insert Now() into the DateAndTime Input. However, we also want to capture entries that were collected hours earlier, even days earlier. I have validation to prevent invalid entries. I've been unsuccessful to find a way to send the data to SharePoint as Type Date and Time. I've been sending it as Single line of text,  but that is not sufficient. We cannot sort properly if it's in Type Single line of text. I've figured out how to send the Now() data using Patch() but that also isn't sufficient.

1 ACCEPTED SOLUTION

Accepted Solutions
Anonymous
Not applicable

@paguirre 

Thanks for this, this is very helpful.

 

If you have validation in-place to ensure users enter data in the correct format then you can simply us the DateTimeValue() function to achieve what you want, eg

// On your Save Button
Patch(Attendance, Defaults(Attendance), {DateAndTime: DateTimeValue(DateandTime_TextInput.Text)})

// where DateandTime_TextInput is the name of your TextInput control

It maybe helpful to read the documentation related to the Date/Time functions here

 

Here is the above in action, Note: the label below the textinput is to demo what's happening in the background

DateandTime_toSP.gif

You mention 'Single line of text' is that the column you are Patching to in SP? This needs to be a Date and Time column with Date and Time selected if you wish to store actual Dates with Times. Otherwise you are just storing Text. You may need to setup a new column rather than changing the one you have already.

 

I'd also recommend setting up another column called DateTimeNumber as a Number/Numeric column. Then adjust your Patch to this:

// adjusted Patch
Patch(Attendance, Defaults(Attendance), 
        {DateAndTime: DateTimeValue(DateandTime_TextInput.Text),
         DateTimeNumber: Value(Text(DateTimeValue(DateandTime_TextInput.Text),"yyyymmdd"))
        }
)

What this will do is add a number to SP that represents your Date. You will then be able to Filter your SP List (in PowerApps) based on this number. There is currently no way to Filter dates in SP by using > or < but this is a workaround. You can then filter by 'Date' by filtering the Number column, eg

 

To filter greater than or equal to 4/1/2020 you can use something like:

Filter(mySPList, DateTimeNumber >= 20200401)

You cannot do the above with a DateTime column. This filtering technique will help you with a large dataset >2000 records.

 

Let me know how you get on.

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

@paguirre 

If you setup your SharePoint column as Date & Time then created the Form in PowerApps the functionality should all be there for you. Is the Now() just to make things easier for users?

 

Can you share some code and screenshots of what you are trying to achieve?

 

Also, depending on how large your SP list will get (>2000 records) you may be better storing the date and time as a number? I can elaborate further if needed.

Text Input: Default: If(IsBlank(DateNow1), ThisItem.DateAndTime, DateNow1)

 

Date and Time Button: OnSelect: UpdateContext({DateNow1: Now()})

 

Save Button: OnSelect: Patch(Attendance, Defaults(Attendance), {DateAndTime: Now())

 

All that gives me is the Date and Time at the moment I press the Save Button. It was pointless to put have the Date and Time Button. I want the Text Input field to be the Date and Time that the user wants it to be either Now() or an earlier Date and Time. We will probably have > 2000 records. We collected records in Attendance that nearly reached 8000 before we used a new SharePoint List.

 

There are only eight columns in the SharePoint List and two of them are generated by SharePoint. For a school getting the Date and Time as Type Date and Time is a big deal. Thanks for replying so quickly.

 

 

 

 

Text Input: Default: If(IsBlank(DateNow1), ThisItem.DateAndTime, DateNow1)

 

Date and Time Button: OnSelect: UpdateContext({DateNow1: Now()}) & UpdateContext({varClock:false})

 

Save Button: OnSelect: Patch(Attendance, Defaults(Attendance), {DateAndTime: Now())

 

All that gives me is the Date and Time at the moment I press the Save Button. It was pointless to have the Date and Time Button. I want the Text Input field to be the Date and Time that the user wants it to be either Now() or an earlier Date and Time. We will probably have > 2000 records. We collected records in Attendance that nearly reached 8000 before we used a new SharePoint List. There are only eight columns in the SharePoint List and two of them are generated by SharePoint. For a school getting the Date and Time as Type Date and Time is a big deal.

The HintText: "M/D/YYYY H:MM ?M" is for validation. The code is correct that's just for the users to realize there's validation. It doesn't match PowerApps guidelines.

TextInput-DateAndTime and Button.png

Anonymous
Not applicable

@paguirre 

Thanks for this, this is very helpful.

 

If you have validation in-place to ensure users enter data in the correct format then you can simply us the DateTimeValue() function to achieve what you want, eg

// On your Save Button
Patch(Attendance, Defaults(Attendance), {DateAndTime: DateTimeValue(DateandTime_TextInput.Text)})

// where DateandTime_TextInput is the name of your TextInput control

It maybe helpful to read the documentation related to the Date/Time functions here

 

Here is the above in action, Note: the label below the textinput is to demo what's happening in the background

DateandTime_toSP.gif

You mention 'Single line of text' is that the column you are Patching to in SP? This needs to be a Date and Time column with Date and Time selected if you wish to store actual Dates with Times. Otherwise you are just storing Text. You may need to setup a new column rather than changing the one you have already.

 

I'd also recommend setting up another column called DateTimeNumber as a Number/Numeric column. Then adjust your Patch to this:

// adjusted Patch
Patch(Attendance, Defaults(Attendance), 
        {DateAndTime: DateTimeValue(DateandTime_TextInput.Text),
         DateTimeNumber: Value(Text(DateTimeValue(DateandTime_TextInput.Text),"yyyymmdd"))
        }
)

What this will do is add a number to SP that represents your Date. You will then be able to Filter your SP List (in PowerApps) based on this number. There is currently no way to Filter dates in SP by using > or < but this is a workaround. You can then filter by 'Date' by filtering the Number column, eg

 

To filter greater than or equal to 4/1/2020 you can use something like:

Filter(mySPList, DateTimeNumber >= 20200401)

You cannot do the above with a DateTime column. This filtering technique will help you with a large dataset >2000 records.

 

Let me know how you get on.

Thank you so much. After reading your reply and going to the site you provided a link to, I came to the conclusion that in the Patch of the Save Button all I needed to change was the following.

 

Save Button: OnSelect: Patch(Attendance, Defaults(Attendance), {DateAndTime: DateTimeValue(Inp_DateAndTime.Text))

 

Now in SharePoint the DateAndTime column that is Type: Date and Time, not Text or Single line of text, records the Date and Time that was set by the Date and Time Button, or by what the user entered under the requirements of the validation. 

 

Yay!

 

Thank you very much. Stay safe and stay healthy.

 

Something to keep in mind with the solution I ended up using. Once the user presses the Date and Time Button the variable that sets Date and Time is set to Now(). As I stated earlier the users were using the Date and Time placed by Now() as a template to satisfy the validation requirements. However, when the Save Button is pressed and the Patch runs the DateTimeValue(Inp_DateAndTime.Text) will be set to Now() not to what the user keyed in. That was frustrating. I developed a solution I do not believe is very elegant but does the job. I made it a two step process that informs the user they need to enter the earlier Date and Time without pressing the Date and Time Button. Those that want to use Now() will press the the Date and Time Button  basically twice. I used twice as a way to train them not to immediately press the Date and Time Button. As I said, it is not an elegant solution. I'm am hopeful that kind Eelman or some other worthy might share some insights. I'm at a lost how to do this efficiently and user friendly.

Thanks,

Anonymous
Not applicable

@paguirre 

I didn't comment on your flow of controls but I figured you may run into some issues. My suggestion would be to add a DatePicker and Dropdowns for Hrs & Mins like in this post https://powerusers.microsoft.com/t5/Building-Power-Apps/Is-there-a-TIME-PICKER/td-p/65252.

 

You would remove the TextInput field and add the DatePicker to that part of you app and put the Hrs & Min Dropdowns beside it.

 

This will take up a little more real estate in your app but will be well worth it. This setup will make validation of the data going to SP so much easier - or you can try to write some regular expression to validate your TextInput?

 

I would then remove the 'Set Date Time to Now()' button and just do a check inside your Patch, ie

Patch(..., {DateandTime: If( IsBlank(DatePickerDate1.SelectedDate), Now(),
            // this part is from the post link
            DatePickerDate1.SelectedDate + Time( Value(DropdownHour.Selected.Value),
            Value(DropdownMinute.Selected.Value), 0)
           }

What this is doing is checking if the DatePicker is Blank(), if it is then use Now() as the DateTime if not then use the selected DateTimes. 

 

I would also add Reset() functions to the OnVisible property of your screen and possibly give the users options to Reset when they want with a 'X' icon. Code for both of these would be:

Reset(DatePickerDate1); Reset(DropdownHour); Reset(DropdownMinute)

For the DatePicker, and the 2 Dropdowns also do the following:

- Set the 'AllowEmptySelection' Property = true, and

- Clear the 'DefaultDate' and 'Default' Properties, ie leave them blank

 

That should do it, I think.

 

Let me know if you get stuck on any of the above and I'll help out.

 

 

Helpful resources

Announcements

Check out the Copilot Studio Cookbook today!

We are excited to announce our new Copilot Cookbook Gallery in the Copilot Studio Community. We can't wait for you to share your expertise and your experience!    Join us for an amazing opportunity where you'll be one of the first to contribute to the Copilot Cookbook—your ultimate guide to mastering Microsoft Copilot. Whether you're seeking inspiration or grappling with a challenge while crafting apps, you probably already know that Copilot Cookbook is your reliable assistant, offering a wealth of tips and tricks at your fingertips--and we want you to add your expertise. What can you "cook" up?   Click this link to get started: https://aka.ms/CS_Copilot_Cookbook_Gallery   Don't miss out on this exclusive opportunity to be one of the first in the Community to share your app creation journey with Copilot. We'll be announcing a Cookbook Challenge very soon and want to make sure you one of the first "cooks" in the kitchen.   Don't miss your moment--start submitting in the Copilot Cookbook Gallery today!     Thank you,  Engagement Team

Announcing Power Apps Copilot Cookbook Gallery

We are excited to share that the all-new Copilot Cookbook Gallery for Power Apps is now available in the Power Apps Community, full of tips and tricks on how to best use Microsoft Copilot as you develop and create in Power Apps. The new Copilot Cookbook is your go-to resource when you need inspiration--or when you're stuck--and aren't sure how to best partner with Copilot while creating apps.   Whether you're looking for the best prompts or just want to know about responsible AI use, visit Copilot Cookbook for regular updates you can rely on--while also serving up some of your greatest tips and tricks for the Community. Check Out the new Copilot Cookbook for Power Apps today: Copilot Cookbook - Power Platform Community.  We can't wait to see what you "cook" up!      

Tuesday Tip | How to Report Spam in Our Community

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   As our community family expands each week, we revisit our essential tools, tips, and tricks to ensure you’re well-versed in the community’s pulse. Keep an eye on the News & Announcements for your weekly Tuesday Tips—you never know what you may learn!   Today's Tip: How to Report Spam in Our Community We strive to maintain a professional and helpful community, and part of that effort involves keeping our platform free of spam. If you encounter a post that you believe is spam, please follow these steps to report it: Locate the Post: Find the post in question within the community.Kebab Menu: Click on the "Kebab" menu | 3 Dots, on the top right of the post.Report Inappropriate Content: Select "Report Inappropriate Content" from the menu.Submit Report: Fill out any necessary details on the form and submit your report.   Our community team will review the report and take appropriate action to ensure our community remains a valuable resource for everyone.   Thank you for helping us keep the community clean and useful!

Community Roundup: A Look Back at Our Last 10 Tuesday Tips

As we continue to grow and learn together, it's important to reflect on the valuable insights we've shared. For today's #TuesdayTip, we're excited to take a moment to look back at the last 10 tips we've shared in case you missed any or want to revisit them. Thanks for your incredible support for this series--we're so glad it was able to help so many of you navigate your community experience!   Getting Started in the Community An overview of everything you need to know about navigating the community on one page!  Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Community Ranks and YOU Have you ever wondered how your fellow community members ascend the ranks within our community? We explain everything about ranks and how to achieve points so you can climb up in the rankings! Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Powering Up Your Community Profile Your Community User Profile is how the Community knows you--so it's essential that it works the way you need it to! From changing your username to updating contact information, this Knowledge Base Article is your best resource for powering up your profile. Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Community Blogs--A Great Place to Start There's so much you'll discover in the Community Blogs, and we hope you'll check them out today!  Community Links: ○ Power Apps ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Unlocking Community Achievements and Earning Badges Across the Communities, you'll see badges on users profile that recognize and reward their engagement and contributions. Check out some details on Community badges--and find out more in the detailed link at the end of the article! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio    Blogging in the Community Interested in blogging? Everything you need to know on writing blogs in our four communities! Get started blogging across the Power Platform communities today! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Subscriptions & Notifications We don't want you to miss a thing in the community! Read all about how to subscribe to sections of our forums and how to setup your notifications! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Getting Started with Private Messages & Macros Do you want to enhance your communication in the Community and streamline your interactions? One of the best ways to do this is to ensure you are using Private Messaging--and the ever-handy macros that are available to you as a Community member! Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Community User Groups Learn everything about being part of, starting, or leading a User Group in the Power Platform Community. Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Update Your Community Profile Today! Keep your community profile up to date which is essential for staying connected and engaged with the community. Community Links: ○ Power Apps  ○ Power Automate  ○ Power Pages  ○ Copilot Studio   Thank you for being an integral part of our journey.   Here's to many more Tuesday Tips as we pave the way for a brighter, more connected future! As always, watch the News & Announcements for the next set of tips, coming soon!

Hear what's next for the Power Up Program

Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram, including a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the link below to sign up today! https://aka.ms/PowerUp  

Welcome to the Power Apps Community

Welcome! Congratulations on joining the Microsoft Power Apps community! You are now a part of a vibrant group of peers and industry experts who are here to network, share knowledge, and even have a little fun! Now that you are a member, you can enjoy the following resources:   The Microsoft Power Apps Community Forums If you are looking for support with any part of Microsoft Power Apps, our forums are the place to go. They are titled "Get Help with Microsoft Power Apps " and there you will find thousands of technical professionals with years of experience who are ready and eager to answer your questions. You now have the ability to post, reply and give "kudos" on the Power Apps community forums! Make sure you conduct a quick search before creating a new post because your question may have already been asked and answered!   Microsoft Power Apps IdeasDo you have an idea to improve the Microsoft Power Apps experience, or a feature request for future product updates? Then the "Power Apps Ideas" section is where you can contribute your suggestions and vote for ideas posted by other community members. We constantly look to the most voted Ideas when planning updates, so your suggestions and votes will always make a difference.   Community Blog & NewsOver the years, more than 600 Power Apps Community Blog Articles have been written and published by our thriving community. Our community members have learned some excellent tips and have keen insights on building Power Apps. On the Power Apps Community Blog, read the latest Power Apps related posts from our community blog authors around the world. Let us know if you would like to become an author and contribute your own writing — everything Power Apps related is welcome!   Power Apps Samples, Learning and Videos GalleriesOur galleries have a little bit of everything to do with Power Apps. Our galleries are great for finding inspiration for your next app or component. You can view, comment and kudo the apps and component gallery to see what others have created! Or share Power Apps that you have created with other Power Apps enthusiasts. Along with all of that awesome content, there is the Power Apps Community Video & MBAS gallery where you can watch tutorials and demos by Microsoft staff, partners, and community gurus in our community video gallery.   Again, we are excited to welcome you to the Microsoft Power Apps community family! Whether you are brand new to the world of process automation or you are a seasoned Power Apps veteran. Our goal is to shape the community to be your ‘go to’ for support, networking, education, inspiration and encouragement as we enjoy this adventure together!   Let us know in the Community Feedback if you have any questions or comments about your community experience.To learn more about the community and your account be sure to visit our Community Support Area boards to learn more! We look forward to seeing you in the Power Apps Community!The Power Apps Team

Top Solution Authors
Top Kudoed Authors
Users online (6,540)