Select to view content in your preferred language

Unix Time?

818
5
01-24-2024 11:24 PM
trashbaby
Emerging Contributor

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!

0 Kudos
5 Replies
BobBooth1
Esri Contributor

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

https://docs.python.org/3/library/datetime.html

0 Kudos
DougBrowning
MVP Esteemed Contributor

format-date(today(), '%m%e%y')  works for me

DougBrowning_0-1706196614171.png

 

0 Kudos
achs
by
Emerging Contributor
  • Hi! 

    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?

  • Not sure about where I should place the expression to convert the date to a regular time.
  • Does it work for previous dates? I'm requesting the date for old documents. 
0 Kudos
DougBrowning
MVP Esteemed Contributor

Yes this would be a calculation and can be part of your concat to make the code you want.

0 Kudos
trashbaby
Emerging Contributor

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!

0 Kudos