Back to catalog
APIs & Integrations

How to Combine Separate Date Time Strings from Bravo Studio

Published 2 min read Video

In Xano's Bravo Studio, the date and time inputs are separate fields. However, there may be cases where you need to combine these inputs into a single timestamp value before storing it in your database. This blog post will guide you through the process of combining date and time inputs using Xano's powerful Function Stack.

Step 1: Extract the Time from the Date-Time String

The time input in Bravo Studio is a date-time string that includes the current date along with the time. To extract just the time portion, you can use the format_timestamp filter in the Function Stack.

format_timestamp('H:i', $time_input)

Here, 'H:i' is the format string that specifies how the time should be displayed. In this case, it will show the time in 24-hour format with leading zeros for the hour and minutes (e.g., 15:30).

You can find a comprehensive list of format characters in Xano's Date and Time documentation.

Step 2: Extract the Date from the Date-Time String

Similar to the time input, you can use the format_timestamp filter to extract the date portion from the date input.

format_timestamp('d M Y', $date_input)

This format string will display the date in the format "day month year" (e.g., 25 Sep 2022).

Step 3: Combine the Date and Time

Once you have the date and time isolated, you can combine them using string concatenation.

$combined_datetime = $formatted_date . ' ' . $formatted_time

This will create a string that looks like "25 Sep 2022 15:30".

Step 4: Parse the Combined String into a Unix Timestamp

To store the combined date-time value in your database, you'll need to parse it into a Unix timestamp format. You can achieve this using the parse_timestamp filter.

parse_timestamp('d M Y H:i', $combined_datetime)

Here, the format string matches the combined date-time string you created in the previous step.

Step 5: Store the Timestamp in Your Database

Finally, you can store the parsed timestamp in a field in your database. Xano will automatically handle the time zone conversion and store the value in UTC format.

$record = [
 'parsed_timestamp' => parse_timestamp('d M Y H:i', $combined_datetime)
];
insert_entry('your_collection', $record);

Replace 'your_collection' with the name of your collection in Xano.

With these steps, you can seamlessly combine date and time inputs in Bravo Studio and store them as a single timestamp value in your Xano database. Remember, Xano's Function Stack is Turing-complete, allowing you to manipulate data in any way you need to meet your application's requirements.