Hey there! In this guide, we'll show you how to combine separate date and time inputs into a single timestamp using Xano and Bravo Studio. This can be useful when you need to store or send a complete date and time as a timestamp in your application.
First, let's set up our inputs. We'll need two separate inputs: one for the date and one for the time. These inputs will come from your Bravo Studio frontend or another source.
In Xano, create two input variables:
Next, we'll combine the date and time inputs into a single variable using Xano's data manipulation functions.
human_timestamp.date input variable.Concatenate filter.time input variable as the second input for the concatenate filter.Now you should have a human_timestamp variable that combines the date and time with a space in between.
Next, we'll parse the human_timestamp into a Unix timestamp using Xano's parse_timestamp filter.
new_timestamp.human_timestamp variable.parse_timestamp filter.Here's where the magic happens! We need to provide the format of our human_timestamp string so that Xano can parse it correctly.
Xano uses PHP's date and time formatting syntax under the hood. You can find the complete list of format characters in the Xano documentation.
For our example date format of "May 4, 2022 4:30 PM", the format string would be:
F j, Y g:i A
Here's what each part means:
F: Full textual representation of the month (e.g., January)j: Day of the month without leading zeros (1 to 31),: Literal comma separatorY: Full numeric representation of the year (4 digits)g: 12-hour format of the hour without leading zeros (1 to 12):: Literal colon separatori: Minutes with leading zeros (00 to 59)A: AM/PM indicator (uppercase)Enter this format string in the parse_timestamp filter and check, update, and save the function.
If you need to handle different time zones, you can set the time zone when parsing the timestamp.
parse_timestamp filter, click on the "Time Zone" field.Europe/Berlin).Finally, you can format and display the parsed timestamp in your desired format and time zone.
format_timestamp filter to your function.America/Los_Angeles).r for a human-readable format like Thu, 21 Dec 2017 16:08:00 +0200).And that's it! You now have a Unix timestamp that you can store, send, or use as needed in your application.
Remember, this process can be adapted to different date and time formats by adjusting the format string in the parse_timestamp filter. Xano's documentation provides a comprehensive list of format characters to help you build the correct format string.
Happy coding (or no-coding)!
Join 100,000+ people already building with Xano.
Start today and scale to millions.
Start building for free