Cara menggunakan date calculation in javascript

Date and time expressions use Date or Duration values to produce a DateTime, Date, Time, Duration, or Number value.

The following sections describe the components for building date and time expressions:

New to expressions and formulas? See also Expressions: The Essentials.

Current date and time functions

  • NOW() for the current DateTime on the user's device.
  • TIMENOW() for the current Time on the user's device. Equivalent to Duration1. See also Duration2.
  • Duration3 for the current Date on the user's device. Equivalent to Duration5. See also Duration6.
  • Duration7 for the current DateTime with no timezone offset (such as, UTC time).

The values returned by Duration8, Duration9, and DateTime0 reflect the timezone offset of the user's device. For example, if the timezone of the user's device is Pacific Standard Time (PST), the value returned is UTC-08:00; if the timezone of the user's device is Hong Kong, the value returned is UTC+8:00.

When the user's device contacts the server to read or update data, the device includes its timezone with the request. The server uses the timezone of the user's device when performing time and date calculations. For example, when the server evaluates security filters and workflow rules that include dates and times.

Time component functions

  • DateTime1 to extract a list of Duration values within a textual value.
  • DateTime3 to extract a list of Time values within a textual value.
  • DateTime5 for the hour component of a specific Duration.
  • DateTime7 for the minute component of a specific Duration.
  • DateTime9 for the second component of a specific Duration.
  • Duration2 for the Time from DateDateTime, or Time.
  • Date6 for count of hours in Duration.
  • Date8 for count of minutes in Duration.
  • Time0 for count of seconds in Duration.

Note that each of Time2, Time3, and Time4 accept as input a Duration value, not a Time value. To convert a Time value to a Duration value, subtract another Time value. For instance, to convert the current time-of-day to a Duration: Duration1.

Date component functions

  • Duration6for the Date from DateDateTime, or Time.
  • Duration7for the DateTime from DateDateTime, or Time.
  • Number2for the day of the month from a Date.
  • Number4 calculates the last day of a month some number of months away, factoring in different month lengths and leap years.
  • Number5 calculates the date of the last day of a week from Date or DateTime.
  • Number8 calculates the date of the last weekday (Monday through Friday) of the month specified by the Date or DateTime value.
  • NOW()1 to extract a list of Date values within a textual value.
  • NOW()3 to extract a list of DateTime values within a textual value.
  • NOW()5 for the month number from a Date.
  • NOW()7for the ISO week number from Date or DateTime.
  • DateTime0 for the day number from a Date. Sunday is DateTime2, Saturday is DateTime3.
  • DateTime4 for the week number from a Date. A week begins on Sunday.
  • DateTime6 returns a date some number of days away, ignoring weekends and other designated days.
  • DateTime7 for the year from a Date.

Formatting dates and times as text

  • DateTime9 accepts a DateTime, Date, or Time and a format string, and returns a text representation.

Legacy operators

For backwards compatibility, we also support the function syntax below for a set of functions that have been supported from the earliest AppSheet release.

Examples

Examples that compute Dates

  • TIMENOW()9: adds one day (a Number) to the current Date.
  • Duration02 : subtracts 3 days (a Number) from the current Date.
  • Duration05 : adds 7 days (a Number) to the Duration07 (a Date).
  • Duration09  : the date of the preceding Sunday.
  • Duration10  : the date of the preceding Monday.

Examples that compute Times

  • Duration11 : adds one hour (a Number) to the current Time.
  • Duration14 : adds 3 hours 3 minutes (a Duration) to the current Time.
  • Duration17 : subtracts 3 hours 3 minutes (a Duration) from the current Time.

Examples that compute DateTimes

  • Duration20 : adds one day (a Number) to the current DateTime.
  • Duration23 : subtracts three days (a Number) from the current DateTime.
  • Duration26 : adds 12 hours 59 minutes (a Duration) to a DateTime value.
  • Duration29  : Creates a DateTime value from a Date value and a Time value.

Examples that compute Durations

  • Duration33 : the Duration between the current Time and 12:30 PM (a Time).
  • Duration37 : the Duration between the current Time and 3:15:30 AM (a Time) on December 30, 1899 (the default Date if none is included).
  • Duration42 : the Duration between the current Date and December 30, 2001 (a Date).
  • Duration46 : the Duration between Duration07 (a Date) at midnight and Duration50 (a Date) at midnight.
  • Duration52 : the Duration between Duration54 and Duration55 (two DateTime values). See also Duration57.

Examples that compute Durations in Days, Months, or Years

  • Duration58 : number of days between today's date and the Date value given in the Duration60 column.
  • Duration61  : the number of days between the start and end dates. It assumes virtual columns Duration62 and Duration63 contain the number of years and months, respectively, computed using the expressions above.
  • Duration64: the number of years between the start and end dates.
  • Duration65 : the number of months between the start and end dates. 

Examples that compare Dates, Times, and DateTimes

  • Duration66: a Duration67 value indicating whether the Date or DateTime value of the Duration70 column value is exactly seven days before today's Date.
  • Duration72: a Duration67 value indicating whether the Date or DateTime value of the Duration70 column value is in the same month as today's date. See also: Number4, Duration3
  • Duration79 : a Duration67 value indicating whether the Date or DateTime value of the Duration70 column value is exactly seven days after today's Date.
  • Duration85 : a Duration67 value indicating whether the DateTime value of the Duration88 column is between the Duration89 and Duration90 column values. See also: Duration91

  • Duration92 : a Duration67 value indicating whether the Date value of the Duration95 column is between the Duration07 and Duration50 column values. See also: Duration91
  • Duration99 : a Duration67 value indicating whether the Date or DateTime value of the Duration70 column is within the past seven days. See also: Duration91
  • DateTime05: a Duration67 value indicating whether the Date or DateTime value of the DateTime09 column is more than a day in the past.
  • DateTime10: a Duration67 value indicating whether the DateTime value of the DateTime13 column is within 24 hours of the current date and time.
  • DateTime14  a Duration67 value indicating whether the DateTime value of the Duration88  column is within 1 hour 30 minutes of the current DateTime.
  • DateTime19 : a Duration67 value indicating whether the minute component of the DateTime or Time value of the current column falls on the quarter hour (that is, is 0, 15, 30, or 45). See also: DateTime23, DateTime24

Examples for scheduling

  • DateTime25 : a Duration67 value for a scheduled periodic event. The DateTime27 value in the first line specifies the starting date of the scheduled periodic event. The DateTime27 value in the second line specifies the ending date of the scheduled periodic event. The DateTime27 value in the third line specifies when the scheduled periodic event should first be triggered. Normally the DateTime27 values in the first and third lines should be identical, but you could specify a slightly later DateTime27 value in the third line to trigger the first scheduled periodic event at a slightly later date. The value 15 in the third line specifies that the scheduled periodic event should be triggered every 15 days after the Date specified in the third line.

Note that when dates are used as constant values within an expression, they must be represented in the DateTime33 format. This doesn't mean your spreadsheet data must use dates in this format: the date representation in your spreadsheets is determined by the locale/language of the spreadsheet.