My script is saving texts
set dataBackupFile to (path to desktop folder as text) & "Note_Backup.txt"
It's time I run the script, this added the date
set myDate to date string of (current date)
set myTime to time string of (current date)
set myDateTime to "--------------------------------------------------------------
" & myDate & " - " & myTime & "
Result :
Wednesday 9 November 2016 -
How can I get AppleScript to count how many time this date is listed on the text file, so I can added to the title
E.g :
Wednesday 9 November 2016 - (2)
My script :
set myDate to date string of (current date)
set filetocheck to (path to desktop folder as text) & "Note_Backup.txt"
set counter to (count text items of myDate) of filetocheck
But the result is 25, while the real result on the files is 38.
The text to count is in this format (Wednesday 9 November 2016):
Wednesday 9 November 2016 -- 10:10:54 - 1 (-41)
0000 other data here
You can do it with text item delimiters, replace linefeed with return if the line delimiter characters are \r
set {TID, text item delimiters} to {text item delimiters, "--" & linefeed & date string of (current date)}
set counter to (count text items of myDateTime) - 1
set text item delimiters to TID
counter will contain the number of occurrences
To check your text file use
set myDate to date string of (current date)
set filetocheck to (path to desktop folder as text) & "Note_Backup.txt"
set theText to read file filetocheck
set {TID, text item delimiters} to {text item delimiters, "--" & linefeed & date string of (current date)}
set counter to (count text items of theText) - 1
set text item delimiters to TID
Related
I have a list of 12 month names, let's say ['AAA', 'BBB', ...]. In reality, they are kind of historical, so not included in any typical locale.
Now I want them to be included into my DateFormat('yMMMMd') instead of the normal names. I am not able to build the date string manually like
var myDateStr = myMonthName + ' ' + myDay + ', ' + myYear; // US
var myDateStr = myDay + '. ' + myMonthName + ' ' + myYear; // DE
because I want to keep the format of the chosen locale nonetheless. The day/month/year order changes with the chosen locale, which I want to keep. I just want to replace the month name. A RegExp replace or similar is not easily possible, I guess, because of the different date formats and language specific month names.
Expected result:
For chosen US locale: AAA 1st, 2022
For chosen DE locale: 1. AAA 2022
of course, every other locale format must be supported...
Do you have any ideas?
Is it possible to just insert custom month names into DateFormat object?
I recently had an idea, which seems to work:
var dateStr = DateFormat('yMMMMd', myLocale).format(myDate);
var monthName = DateFormat('MMMM', myLocale).format(myDate);
return dateStr.replaceFirst(monthName, 'AAA');
// or
return dateStr.replaceFirst(monthName, myHistoricalNames[myDate.month - 1]);
First create the normal date string to receive the locale's date format.
Calculate another date string which only includes the locale's month name. Now I know the string which I need to replace in dateStr no matter which language I choose.
Replace the month name with my custom month name.
I have a table with order date, usually most of the data is date, but sometimes I need to write text, so that's why I want to choose text as data type. My data in the table is as follows:
BestellDatum
20.10.2021
22.10.2021
03.01.2022
02.01.2022
23.01.2022
I have a query I created from this table and a form I created from this query. In this form I want to filter by date range (two text fields, names txt.orders_from and txt.orders_to). My code for this:
Private Sub SearchbyDateRange_Click()
Dim strCriteria, task As String
Me.Refresh
If IsNull(Me.txt.orders_from) Or IsNull(Me.txt.orders_to) Then
MsgBox "Please enter a date range"
Me.txt.orders_from.SetFocus
Else
strCriteria = "([OrderDate] >= #" & Format(Me.txt.orders_from, "yyyy/mm/dd") & "# And [OrderDate] <= #" & Format(Me.txt.orders_to, "yyyy/mm/dd") & "#)"
task = "select * from qryOrders where(" & strCriteria & ") order by [OrderDate]"
DoCmd.ApplyFilter task
End If
End Sub
However, if I try to search for the period from 20.10.2021 to 03.01.2022, for example, no dates are displayed. This code works when the OrderDate column has the data type as date/time. Is there anything I can do to use this code with data type as Text or do you have any other idea?
Format expects a Date as the first parameter and you are feeding it a Text. Instead of trying to convert text into different text what you need is a way to convert your text into a date.
The function you are looking for to convert text to a date value and make date comparisons is CDate.
I am not 100% sure CDate will be able to read your specific date format but it is worth a try. If not you will have to do the hard work of breaking it down into a text array and recombining it to a more compatible format.
Convert your text dates to true dates:
strCriteria = "CDate(Replace([OrderDate], ".", "-")) >= #" & Format(Me.txt.orders_from, "yyyy\/mm\/dd") & "# And CDate(Replace([OrderDate], ".", "-")) <= #" & Format(Me.txt.orders_to, "yyyy\/mm\/dd") & "#"
I am using dlookup (date = date) its fine when the date is of "May" but when I put date of any other month like 1/6/19 the dlookup remains silent.
in Dlookup if date is of MAY its fine but not working when date id of JUN the code I am using is as below
Me
Total = DLookup("Total", "Dailycash", "Cdate =#" & sdate & "#")
Apply a proper format to the date value expression:
Total = DLookup("Total", "Dailycash", "Cdate = #" & Format(sdate, "yyyy\/mm\/dd") & "#")
I'm trying to create a script to log my current time and my finish time
do a specific action them sent an email with this same time variable and create a calendar event with this time variable :
set FinsihDate to (current date) + 10 * hours + 30 * minutes
set startingDate to (current date)
set plistR to {FinsihDate:FinsihDate, starteddate:current date}
tell application "System Events"
set plistf to make new property list file ¬
with properties {name:"~/Desktop/MY_Time.plist"}
set plistf's value to plistR
end tell
## Email
property lastWindowID : missing value
tell application "Mail"
set windowIDs to id of windows
if windowIDs does not contain lastWindowID then
set newMessage to make new outgoing message with properties {subject:"Started early", content:"Hi ..., \n \nI started early today : " & (current date) & ", I will leave at " & FinsihDate & "\n \nKind Regards,\nKevin " & return & return}
tell newMessage
set visible to true
make new to recipient at end of to recipients with properties {name:"Name", address:"#apple.com"}
end tell
activate
set lastWindowID to id of window 1
else
tell window id lastWindowID
set visible to false
set visible to true
end tell
activate
end if
end tell
set startDate to date (current date)
set endDate to date FinsihDate
tell application "Calendar"
tell (first calendar whose name is "calendar")
make new event at end of events with properties {summary:"Work", start date:startDate, end date:endDate, description:"ITS Fraud Prevention", location:"Apple"}
end tell
end tell
Time format
the time format on the email is " Monday 4 June 2018 at 14:25:57," when I just want 14:25
I tried this :
set myTime to (time string of (current date)) + 10 * hours + 30 * minutes
Result: error "Can’t make \"14:27:02\" into type number." number -1700
from "14:27:02" to number
Calendar
When creating the Calendar event I have this error
error "Can’t get date (date \"Monday 4 June 2018 at 14:29:34\")."
number -1728 from date (date "Monday 4 June 2018 at 14:29:34")
Thanks for itemising the individual errors that you encountered and want fixing. This made is so much easier for me to read this question and decide it was one I wanted to answer, because I don't actually have to test your script at all as I can immediately see what the problems are:
① Your parentheses are in the wrong place. Change this:
set myTime to (time string of (current date)) + 10 * hours + 30 * minutes
to this:
set myTime to time string of ((current date) + 10 * hours + 30 * minutes)
② The error indicates that you've tried to take a variable of type date and then declare it again as type date. AppleScript doesn't like this.
Change these two lines:
set startDate to date (current date)
set endDate to date FinsihDate
to this:
set startDate to (current date)
set endDate to FinsihDate
I haven't tested the rest of the script.
P.S. You misspelled your variable name FinsihDate (which I assume is meant to be FinishDate). However, it's misspelled consistently throughout the script, so it doesn't make any practical difference.
I have an Access 2013 form which has two unbound date fields, FromDate and ToDate. I insert these into a table (TblGuestBooking) which has an autonumber key field, so this doesn't feature in the SQL statement to follow.
If the FromDate and ToDate are in the same month, the dates are entered as dd/mm/yy, the format of the form field. If, however, the From date is in one month and the to date is in the next month or later month, the format changes to mm/dd/yy for the subsequent months.
for example 26/2/14 to 3/3/14 results in the following table entries:
26/02/14,
27/02/14,
28/02/14,
03/01/14,
03/02/14,
03/03/14
This is the code snippet I am using to put the dates into the table (BookingID is obtained from the form.)
Dim BookingDate As Date
Dim SQLString As String
....
BookingDate = FromDate
Do
SQLString = "INSERT INTO TblGuestBooking ([BookingDate], [BookingID]) VALUES (#" & BookingDate & "#" & "," & Me.GuestSuiteBookingID & ")"
DoCmd.SetWarnings False
DoCmd.RunSQL SQLString
DoCmd.SetWarnings True
BookingDate = BookingDate + 1
Loop Until BookingDate = ToDate + 1
If you've read this far, thank you for your time. If you can help me out, many, many thanks.
When processing date literals (text values enclosed by "hash marks" #) Access SQL will always interpret ambiguous xx-yy-zzzz dates as mm-dd-yyyy, regardless of the regional setting in place on the computer. So, if your machine is configured to display short dates as dd-mm-yyyy and you create an Access query that uses #04-02-2014# it will always be interpreted as April 2, not February 4.
The solution is to always format date literals as unambiguous yyyy-mm-dd values. In your case, instead of
... VALUES (#" & BookingDate & "#" ...
you would use something like
... VALUES (#" & Format(BookingDate, "yyyy-mm-dd") & "#" ...
In my case I've used following code for an ASP page that create and update a Date field in Access database.
strDay = Request("Day")
strMonth = Request("Month")
strYear = Request("Year")
InputDate = strYear & "-" & strMonth & "-" & strDay
if IsDate(InputDate) Then
InsertDate = CDate(InputDate)
else
'if date typed wrong, use Todays Date
InsertDate = Date()
end if
SQLUPD = "UPDATE MyDataBase SET DateField = '"& FormatDateTime(InsertDate, vbShortDate) &"'"
SQLINS = "INSERT INTO MyDataBase (DateField, Alist, Atype, Acomment) VALUES ('"& FormatDateTime(InsertDate, vbShortDate) &"', .....
Then all sorting and output opration with dates are going well.