INFO: 1 new highlights
INFO: Saved last update: 2025-03-01T14:54:58.858+0000
10349:10355: syntax error: Expected end of line but found class name. (-2741)
⁉️ Error saving Date
ERROR: Error saving bookmark Date
tell application id "DNtp"
set theGroup to (incoming group of database "Notes")
-- search for an existing record matching title
set searchResults to search "name:\"Date\"" in theGroup
if searchResults is not {} then
set theRecord to item 1 of searchResults
else
set theRecord to create record with {name:"Date", type:markdown, URL:"https://acrobatfaq.com/atbref10/index/Automating_Tinderbox/Coding/Action_Code/Operators/Full_Operator_List/date_dateStr.html", content:"title: \"date(dateStr)\"
source: https://acrobatfaq.com/atbref10/index/Automating_Tinderbox/Coding/Action_Code/Operators/Full_Operator_List/date_dateStr.html
date: 2025-03-01 06:55
tags:
description:
[source](https://acrobatfaq.com/atbref10/index/Automating_Tinderbox/Coding/Action_Code/Operators/Full_Operator_List/date_dateStr.html)
# date(dateStr)
------------------------------------------------------------------------
**Operator Type:**
**Operator Scope of Action:**
**Operator Purpose:**
**Data Type Returned:**
**Operator First Added:**
**Operator in Current Baseline:**
**Operator Last Altered:**
Function \\[[other Function type actions][1]\\]
Item \\[[operators of similar scope][2]\\]
Date-time \\[[other Date-time operators][3]\\]
Date \\[about [Date][4] data type\\]
v4.0.0
Baseline
As at baseline
------------------------------------------------------------------------
**date(dateStr)**
This constructs a Date-type object from a quoted string or string expression. Note there is an alternate method for specifying a date using the discrete elements (year, month, etc.), see [here][5].
Originally, this is not necessary and Tinderbox would coerce the bare **dateStr** to a Date-type automatically. This can still happen but best practice, now action code is more complex, is to be more explicit as to intent by using the **date()** operator. (See [format()][6] and [.format()][7] to convert dates into strings).
Note that in the examples below, whilst the date() operator creates Date-type data, the examples below are actually coercing it back into a string. As formatting is locale dependent and as aTbRef is written using a UK locale (`en-GB`), the examples below use day-month order. Thus should be correct for most of the world except the USA and the Philippines where moth-day order is used and where readers will need to transpose the month and day segments of the example output. The action code shown is being exported via `^value()^`.
Note that the seconds element of stored Date data is ignored (from v5 onwards). Thus, if present in the Date, seconds are not used and instead are coerced to '00'.
Default: using `$MyDate = date(\"24/10/2009\");` will set \\$MyDate to a \"`24 Oct 2009 at 22:24:27`\" (24 October 2009). If no time is supplied hh:mm:ss are set at current system time when \\$MyDate is set. In the example here, the equivalent date is set on the fly via `^value()^` so the time is the system time as at exporting the note to HTML. The resulting string is the same as you see for a date displayed as a Displayed Attribute. The exact format will depend on the users international settings---also see Document Settings ▸ [Displayed Attributes date format][8].
Now, as above but providing an explicit time element, omitting seconds: `$MyDate = date(\"24/10/2009 01:30:22\")` gives \\$MyDate a value of \"`24 Oct 2009 at 01:30:00`\"; the specified time gets used, with the seconds added in as per the system clock. If providing a full hh:mm:ss string this is honoured.
But, if you use a [date formatting string][9], you get a formatted *string* of the date:
> `$MyString = date(\"24/10/2009 01:30:00\").format(\"l\");` gives \\$MyString a value of \"`24/10/2009\"`
or:
> `$MyString = date(\"24/10/2009 01:30:00\").format(\"*\");` gives \\$MyString a value of \"`Sat, 24 Oct 2009 01:30:00 +0000`\"
The two methods are equivalent, note also the change of format due to use of a [date format][9] string.
An attribute can also provide part of the input:
> `$EndDate = date($StartDate+\"7 days\");`
With care this can be extended. In the following, \\$MyString is \"7 days\" and \\$MyNumber is 7. The outcome is that \\$MyDateA/B/C are all set to the same date:
> `$MyDateA = date($MyDate+\"7 days\");`
> `$MyDateB = date($MyDate+$MyString);`
> `$MyDateC = date($MyDate+($MyNumber+\" days\"));` *note the extra parentheses here are optional but suggested*
------------------------------------------------------------------------
**See also**---notes linking to here:
- [Checking and setting Time correctly in Date data][10]
- [Keywords for Date-Type Attributes][11]
- [date(yearNum, monthNum, dayNum\\[, hourNum, minNum\\])][5]
------------------------------------------------------------------------
------------------------------------------------------------------------
Quicklinks: [Attributes][12] \\| [Action Codes][13] \\| [Export Codes][14] \\| [Designators][15] \\| [Date Formats][9] \\| [Shortcuts Look-up][16]\\| [aTbRef Site Map][17] \\| [aTbRef Search][18]
------------------------------------------------------------------------
*\\[Last exported: 4 Feb 2025, using Tinderbox v10.1.0\\]*.
Content, Tinderbox export and web template design all by Mark Anderson, ([Shoantel Limited][19]).
If this resource has helped you, please consider donating to help support aTbRef's ongoing development.
------------------------------------------------------------------------
A Tinderbox Reference File ('aTbRef') by [Mark Anderson][20] is licensed under a
Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
.
[![][21]][22] Based on a work at [atbref.com/][20] \\[Also see aTbRef CC licence [Attribution & Waiver][23] information\\].
------------------------------------------------------------------------
Search within aTbRef10 website:
[aTbRef Search][18] (aTbRef fuzzy search).
Using DuckDuckGo (Cmd+click for results in new window/tab):
Using Google (uses pop-up results window):
------------------------------------------------------------------------
[1]: https://acrobatfaq.com/atbref10/index/Automating_Tinderbox/Coding/Action_Code/Action_Operator_Functional_Types/Function_actions.html
[2]: https://acrobatfaq.com/atbref10/index/Automating_Tinderbox/Coding/Action_Code/Action_Operator_Scope/Item-based_operators.html
[3]: https://acrobatfaq.com/atbref10/index/Automating_Tinderbox/Coding/Action_Code/Action_Operator_Types/Date-time_operators.html
[4]: https://acrobatfaq.com/atbref10/index/Automating_Tinderbox/Use_of_Attributes/Attribute_Data_Types/Date-Type_Attributes.html
[5]: https://acrobatfaq.com/atbref10/index/Automating_Tinderbox/Coding/Action_Code/Operators/date_yearNum_monthNum_dayNum_hourNum_minNum.html
[6]: https://acrobatfaq.com/atbref10/index/Automating_Tinderbox/Coding/Action_Code/Operators/format_dataStr_formatStr_additionalArguments.html
[7]: https://acrobatfaq.com/atbref10/index/Automating_Tinderbox/Coding/Action_Code/Operators/Date_format_formatStr.html
[8]: https://acrobatfaq.com/atbref10/Preferences_Document_Settings/Document_Settings/Text/Displayed_Attributes_date_format.html
[9]: https://acrobatfaq.com/atbref10/Formatting/Date_Formats.html
[10]: https://acrobatfaq.com/atbref10/index/Automating_Tinderbox/Coding/Checking_and_setting_Time_correctly_in_Date_data.html
[11]: https://acrobatfaq.com/atbref10/index/Automating_Tinderbox/Use_of_Attributes/Keywords_for_Date-Type_Attributes.html
[12]: https://acrobatfaq.com/atbref10/index/Automating_Tinderbox/Use_of_Attributes/Attribute_Listings/System_Attribute_List.html
[13]: https://acrobatfaq.com/atbref10/index/Automating_Tinderbox/Coding/Action_Code/Full_Operator_List.html
[14]: https://acrobatfaq.com/atbref10/index/Automating_Tinderbox/Export_Codes/Export_Codes_-_Full_Listing.html
[15]: https://acrobatfaq.com/atbref10/index/Automating_Tinderbox/Coding/Designators.html
[16]: https://acrobatfaq.com/atbref10/Keyboard_Shortcuts/Reverse_Look-up_Map.html
[17]: https://acrobatfaq.com/aTbRef_Site_Map.html
[18]: https://acrobatfaq.com/search.html
[19]: https://www.shoantel.com/services.html
[20]: https://atbref.com/
[21]: https://licensebuttons.net/l/by-nc-sa/4.0/88x31.png
[22]: https://creativecommons.org/licenses/by-nc-sa/4.0/
[23]: https://acrobatfaq.com/atbref10/About_aTbRef/Creative_Commons_Licence.html"} in theGroup
end if
if theRecord is missing value then
error "Failed to create record"
end if
-- set the URL of the entry to the bookmark url
set URL of theRecord to "https://acrobatfaq.com/atbref10/index/Automating_Tinderbox/Coding/Action_Code/Operators/Full_Operator_List/date_dateStr.html"
-- add annotation as Finder comment
set comment of theRecord to "**Summary**: The `date(dateStr)` function creates a Date-type object from a string that represents a date. It is recommended to use this function explicitly to avoid confusion, especially when dealing with different date formats across locales. Additionally, you can manipulate dates by adding days or specifying times, with the seconds being ignored in the stored Date data from version 5 onwards.
### Highlights
Originally, this is not necessary and Tinderbox would coerce the bare **dateStr** to a Date-type automatically. This can still happen but best practice, now action code is more complex, is to be more explicit as to intent by using the **date()** operator. (See [format()](https://acrobatfaq.com/atbref10/index/Automating_Tinderbox/Coding/Action_Code/Operators/Full_Operator_List/format_dataStr_formatStr_additionalArguments.html) and [.format()](https://acrobatfaq.com/atbref10/index/Automating_Tinderbox/Coding/Action_Code/Operators/Full_Operator_List/Date_format_formatStr.html) to convert dates into strings).
- [Highlight link](https://read.readwise.io/read/01jn9380em3hby49n5eqn0sd96)
"
-- add an annotation link (same content as Finder comment)
set theAnnotation to annotation of theRecord
if theAnnotation is not missing value then
update record theAnnotation with text "**Summary**: The `date(dateStr)` function creates a Date-type object from a string that represents a date. It is recommended to use this function explicitly to avoid confusion, especially when dealing with different date formats across locales. Additionally, you can manipulate dates by adding days or specifying times, with the seconds being ignored in the stored Date data from version 5 onwards.
### Highlights
Originally, this is not necessary and Tinderbox would coerce the bare **dateStr** to a Date-type automatically. This can still happen but best practice, now action code is more complex, is to be more explicit as to intent by using the **date()** operator. (See [format()](https://acrobatfaq.com/atbref10/index/Automating_Tinderbox/Coding/Action_Code/Operators/Full_Operator_List/format_dataStr_formatStr_additionalArguments.html) and [.format()](https://acrobatfaq.com/atbref10/index/Automating_Tinderbox/Coding/Action_Code/Operators/Full_Operator_List/Date_format_formatStr.html) to convert dates into strings).
- [Highlight link](https://read.readwise.io/read/01jn9380em3hby49n5eqn0sd96)
" mode replacing
else
set annotation of theRecord to create record with {name:((name of theRecord) as string) & " (Annotation)", type:markdown, content:"**Summary**: The `date(dateStr)` function creates a Date-type object from a string that represents a date. It is recommended to use this function explicitly to avoid confusion, especially when dealing with different date formats across locales. Additionally, you can manipulate dates by adding days or specifying times, with the seconds being ignored in the stored Date data from version 5 onwards.
### Highlights
Originally, this is not necessary and Tinderbox would coerce the bare **dateStr** to a Date-type automatically. This can still happen but best practice, now action code is more complex, is to be more explicit as to intent by using the **date()** operator. (See [format()](https://acrobatfaq.com/atbref10/index/Automating_Tinderbox/Coding/Action_Code/Operators/Full_Operator_List/format_dataStr_formatStr_additionalArguments.html) and [.format()](https://acrobatfaq.com/atbref10/index/Automating_Tinderbox/Coding/Action_Code/Operators/Full_Operator_List/Date_format_formatStr.html) to convert dates into strings).
- [Highlight link](https://read.readwise.io/read/01jn9380em3hby49n5eqn0sd96)
"} in (annotations group of database of theRecord)
end if
-- add any Readwise document tags
set AppleScript's text item delimiters to ","
set theList to every text item of ""
if theList is not {} then
set tags of theRecord to theList
end if
-- Set thumbnail if available
if "https://readwise-assets.s3.amazonaws.com/static/images/article4.6bc1851654a0.png" is not ""
set thumbnail of theRecord to "https://readwise-assets.s3.amazonaws.com/static/images/article4.6bc1851654a0.png"
end if
end tell
ERROR: Error undefined local variable or method 'cmd' for an instance of Import
["/Users/david/bin/readwise_to_devonthink.rb:861:in 'Import#content_for_title'", "/Users/david/bin/readwise_to_devonthink.rb:877:in 'Import#highlight_markdown'", "/Users/david/bin/readwise_to_devonthink.rb:517:in 'block in Import#save_all'", "/Users/david/bin/readwise_to_devonthink.rb:516:in 'Array#each'", "/Users/david/bin/readwise_to_devonthink.rb:516:in 'Import#save_all'", "/Users/david/bin/readwise_to_devonthink.rb:993:in ''"]