Converting a `localdatetime` to a datetime`

For a scheduling app, I am receiving a time stamp as something similar to a localdatetime. Specifically, it’s generated by an HTML datetime-local input, as YYYY-MM-DDTHH:MM, and that works just fine when passed to localdatetime.

The node representing the appointment location has a timezone property, so I was thinking of building a localdatetime and then attaching the time zone after that, but I can’t figure out how to convert a localdatetime to a datetime by bolting on a given timezone. datetime(localdatetime($timestamp)) adds a time zone, but sets it to UTC and that’s not quite what I want. I want to be able to provide that time zone.

An alternative I thought of was to break down the localdatetime into component parts and rebuild the datetime from that, but doesn’t return datetime-compatible map keys. What I’m looking for is something like this:

MATCH (office:Office { id: $office_id })
CREATE (appt:Appointment {
  timestamp: datetime(
    { timezone: office.timezone }

Obviously this doesn’t work since datetime only takes a single argument but is there a way to do something like this?

Hi @jgaskins,,

You can change localdatetime to string and the use datetime eg.
''' return datetime(tostring(localdatetime('2020-05-21T21:02'))+'z') '''

You may want to review the temporal types documentation, there are sections for creating values based upon other temporal type values, check out the examples:

TIL datetime() accepts a datetime: key. For some reason I thought you could only pass another temporal type as the parameter and it would restructure it into the map. Thanks @andrew.bowman, this is precisely what I was looking for:

  datetime: localdatetime('2020-05-23T18:30'),
  timezone: 'America/New_York'
# => "2020-05-23T18:30:00[America/New_York]"