Skip to main content

Notifications

Building Power Apps
Suggested answer

Collecting Date and Time

Posted on by 11
Hi Guys,
 
Im a bi of a Novice to Power Apps, and have a query around Collecting Dates & Times.
 
I have created a Text Input Box, which I am collecting the Date & Time using the the Now () Formula.
 
The issue I have, is that I am trying to collect this Time and Date to post into my Data Verse Table
 
Have tried a whole host of different Collect formulas, this is the latest one which failed, and below it the response from CoPilot
 
Collect(
    'Out Of Ours Tables',
    {'Date & Time':Date_Time.SelectedDate +Time(Value(HourValue1.Selected.Value),Value(MinuteValue1.Selected.Value)}
    );
 
Response from CoPilot
The expression was intended to collect a record into the 'Out Of Ours Tables' table with the current date and time based on the selected date, hour, and minute values.
However, there are multiple errors in the expression such as unexpected characters,
invalid names ('SelectedDate', 'HourValue1', 'MinuteValue1'), using the '.' operator on error values, invalid arguments for the 'Value' function,
and an incorrect number of arguments for the 'Add' function.
 
Any help would be hugely welcome
 
Thanks
Dan
  • DM-12091425-0 Profile Picture
    DM-12091425-0 11 on at
    Collecting Date and Time
    Hi @timl
     
    Have attempted this, had to make a few changes based on the feedback from Co-Pilot, but to no avail :( 
     
    Patch('Global Out Of Hours Tables',Defaults('Global Out Of Hours Tables'),(Date_Time':DateTime(Year(DateValue1.SelectedDate),
             Month(DateValue1.SelectedDate),
             Day(DateValue1.SelectedDate),
             Value(HourValue1.Selected.Value), Value(MinuteValue1.Selected.Value)))
     
     
    This the response I get from Co-Pilot:
    The expression was intended to patch a new record into the 'Global Out Of Hours Tables' table with the date, month, day, hour, and minute values extracted from the DateValue1, HourValue1, and MinuteValue1 controls.
    However, there are multiple errors in the expression such as missing operators, incorrect syntax, unrecognized variables, and invalid arguments for the Value function and Patch function.
     
    Its also saying it does not like "DateValue1" Should I be replacing this with something? (Apologies for the noob questions)
     
     
    It was also expecting something here
  • timl Profile Picture
    timl 31,455 on at
    Collecting Date and Time
    Hi Dan,
    The following is a safe way to retrieve the date and time irrespective of locale (eg, it'll work for US and countries that use the dd/mm/yy format)
     
    DateTime(Year(DateValue1.SelectedDate), 
             Month(DateValue1.SelectedDate), 
             Day(DateValue1.SelectedDate), 
             Value(HourValue1.Selected.Value), Value(MinuteValue1.Selected.Value)
    )
    
     
    If you're looking to add a record to the 'Out of Ours Tables', I'd suggest that you call the Patch function rather than Collect.
     
    Patch(
      'Out of Ours Tables',
      Defaults('Out of Ours Tables'),
      {
         'Date & Time':DateTime(Year(DateValue1.SelectedDate), 
             Month(DateValue1.SelectedDate), 
             Day(DateValue1.SelectedDate), 
             Value(HourValue1.Selected.Value), Value(MinuteValue1.Selected.Value)
           )
      }
    )
     
    This syntax assumes that you've added the datepicker and hour/time dropdown boxes to your screen. If you want to save the contents of a textbox called Textbox1, the syntax would look like this:
     
    Patch(
      'Out of Ours Tables',
      Defaults('Out of Ours Tables'),
      {
         'Date & Time':DateTimeValue(Textbox1.Text)
      }
    )
     
  • DM-12091425-0 Profile Picture
    DM-12091425-0 11 on at
    Collecting Date and Time
    Hi FLMike,
     
    Have attempted this and it feels like its on the right track for sure (I originally copied the + stuff from another forum haha.
     
    The Date_Time is a Text Input Box with a Now() formulae so the user doesnt have to capture it manually or clicking buttons.
     
     
     
    The Table is a Data Verse table with a Date and Time Input format:
     
    Have tried a couple of times and its saying DateTimeValue is not a recognised property of the Date_Time Variable (Which is my text input using Now() Formulae) 
     
    Does this make sense?
     
    Thanks
    Dan
     
  • Suggested answer
    FLMike Profile Picture
    FLMike 23,361 on at
    Collecting Date and Time
    Hi
     
    You don't use the + sign to add stuff like that.
     
    You should use the DateTimeValue function to convert all the stuff you have above into that
    So just format it as a string, wrap it with DateTimeValue 
     
    So like 
     
    DateTimeValue(Date_Time.SelectedDate & " " & HourValue1.Selected.Value & ":" & MinuteValue1.Selected.Value & " PM")
     
    Something like that. Since I cannot see your .Value values i am not sure its correct
     
    But give that a go
     
    Mark as the answer if this solves your issue please
     

Helpful resources

Quick Links

Welcome to the Power Platform…

We are thrilled to unveil the newly-launched Power Platform Communities!…

Community Update Sept 16…

Power Platform Community Update…

Welcome to the new Power Platform Community!…

We are excited to announce our new Copilot Cookbook Gallery in the Community…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 140,745

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 63,355

Leaderboard