Text to date expression help

I’ve created a task with a natural language date component instead of using the date and time picker. I like the aesthetic, but I’m running into a wall on the backend converting the text to a date and can use some help.

Here’s the Task pop up:

Screenshot 2023-03-02 at 12.45.05 AM

Looking at the Due Date section, you can see that I’ve added natural language to the date picker. For time, I’ve created an option set with 24 hour time broken down into 15 min increments.

What I want to do is combine these two items into a date.

Here’s a look at the editor with the logic for the natural language date info.

I have looked through historical posts, and it appears Expressions from the Toolbox plug-in might be the ticket.

I have created an expression that attempts to combine the expression that I have for the natural language date info in the editor with custom state data (dash’s schedule time display) that I have for the time selection (10:45 pm etc).

I’m assuming that I’ve botched the expression in the expression element, and I’m looking for ideas.

Thanks in advance for your feedback.

I’m not sure how you’ve got it set up to get the 15 min increments, but working with time in Bubble (and any coding language) can be tricky. Especially as Bubble translate’s things to natural language.

Basically, you’ll need to round the time down to the nearest hour, then add the minute increment that you want, to get the desired result.

Here’s a simple expression using +15 minutes:

Result (ignore that fact that it’s going from 8:27 down to 8:15, it will work with your custom increment):
timeline change

Hope that helps!

A note on working with time: Time in Bubble is translated from UNIX time (1677785595) to something we can understand as humans. Some operations just change this UNIX time and you get this result to work with and some will return a number (e.g. extract hour = 8). It pays to keep a note of which value you’re working with at the end of an operation when modifying times.

Again, thank you for your help and feedback!

Dealing with dates, times, and bookings/calendars is extremely complicated! You’ve said it, and I’ve read it over again.

I’m going to try to be as specific as possible. Some of this is a recap of what you know so bear with me.

For this project, I’m working on scheduling tasks in a CRM. When you create a task, you need to schedule when it’s due and if you’d like a reminder that it’s coming due.

Here’s a screenshot of the customer-facing view:

Screenshot 2023-03-02 at 6.42.06 PM

Instead of the standard date and time picker, I’ve created custom drop downs for Due Date and Set Reminder. Although this method adds complication, it’s aesthetically pleasing and natural language.

The drop downs are comprised of 3 different option sets.

Due date:

Screenshot 2023-03-02 at 6.46.50 PM

Time Selection (in 15 min increments for 24 hours):

Screenshot 2023-03-02 at 6.48.13 PM

Set Reminder:

Screenshot 2023-03-02 at 6.50.12 PM

Custom Date is the final option for the Due Date and Reminder option sets. When that is selected, a standard date and time picker appears like so:

Screenshot 2023-03-02 at 6.53.53 PM

Everything on the UI side works fine, but the devil is in the backside details.

You graciously helped me arrive at the following formula to translate the content in the drop down Due Date to read (tomorrow (March 2).

Screenshot 2023-03-02 at 6.57.20 PM

My challenge is this formula converts the data to text, and I need to store it as a date. This goes for the info in the reminder drop down as well. And to further complicate things, because the time field is an independent element, it needs to be merged with the ensuing dates for Due Date and Reminders. To clarify further, Due Date is a date, Time is a Time, and Reminder is a Time. Dates need to be merged with Time and Times need to be Merged with Dates and saved in the DB accordingly. Hope that makes sense.

Any questions about any of this?

P.S. Regarding your gif above, you can schedule your task for a date in 15 min increments of the 24 hour clock e.g., 3/6/2023 at 7:30 or 7:45 or 9:15

@chrismilleratx ahh gotcha.

To save as a date, delete the part in the formula where it says ‘format as’ or extract(x) as these are converting the date to a text or number. Dates are actually UNIX time stamps, as I’ve included in the GIF below, this might make it clearer why we can’t just add day to time etc from text.

If you want to just get this to work, you could add a minutes attribute to each ‘Time Selection’ option set e.g (15:45 = 945 minutes from 12:00am) - but there’s got to be a simpler way to implement this… as this will have to be done 96 times. You could have a play around with streamlining this

Round down current day to 12:00am → add your days/weeks etc → add the amount of minutes to reach desired time

Here’s an example with a couple of time options:
Timelines example

I think there’s definitely a streamlined approach out there! perhaps a plugin? I think there are some time pickers also.

Let me know if that helps.

Yeah, I think it’s going to take a complex expression to nail it.

I noticed that formatting was the issue with changing dates to text, but I’m so new at expressions, I haven’t found another alternative yet. Heck, I’ve learned a ton from you just seeing how you use nested expressions. Cool stuff!

I’ll play around with this and get it figured out. Then, I’ll have to figure out how to make a work week M-F and have the formula exclude Sat and Sun. Ha!

In the meantime, I’m probably going to use two date and time pickers so I can just keep the project moving. I’ll work on this stuff in the background and implement it when I get it figured out.

I owe you a cold beer, friend. Thanks!

No worries, good luck!

Hopefully someone else from the forum will chime in with another approach.

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.