Hello,
I would like to incorporate a MMDDYY date format into a Sample ID. The Sample ID should be formatted into a standard "Facility Name-Date-Material Type-Sample Replicate" format.
The date space in that format, pulling from a date question with the default set to today(), January 24, 2024, is showing up as 1706126400000.
So my Sample ID is something like BA-1706126400000-OCC-1. I've referenced this article many times and haven't figured out what I'm doing wrong - https://community.esri.com/t5/arcgis-survey123-blog/dates-and-time-in-survey123/ba-p/895528.
I do know that that string of numbers is the Unix code, or seconds since 1970..for some reason.
I'm getting errors when using the decimal-date calculation and format-date calculations.
Help!
You can use the datetime module to convert to string representation. You can also just get dates, using the datetime module date method. You have to specify the string format, like this:
import datetime
from datetime import date, timedelta
nowstring = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
# get 14 days ago date
prev_days = date.today() - timedelta(14)
print(nowstring)
print(prev_days)
20240125094503 2024-01-11
format-date(today(), '%m%e%y') works for me
I am trying to convert a UNIX date to regular time, to concatenate the date with other data such as name and barcode.
Should the expression format-date(today(), '%m%e%y') be placed in the "calculation" field?
Yes this would be a calculation and can be part of your concat to make the code you want.
From user abureaux, who assisted me on another topic:
I did make one addition to your document: sample_date_calc. If you reference a date field, you will get the UNIX time rather than human time (feel free to change the format to whatever suits you best):
This is what finally got it to work for me!