There is a similar question here but using calc however teh answer woul seem to be calc specific. I would like to write a macro in libre writer that inserts the current date, a comma and space then the current date + 2 days, a comma and space then the current date + 14 days.
Recording a marco of date insertion gives the following however to be honest i dont have a clue how to interpret this code and can find little help on the net.
sub recall_period
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
rem ----------------------------------------------------------------------
dispatcher.executeDispatch(document, ".uno:InsertDateField", "", 0, Array())
end sub
Would appreciate any helps or ides. Cheers
Damian
Andrew Pitonyak's macro document has a number of examples of working with dates.
Section 7.7.1 shows an example of inserting a date field into a Writer document.
Section 7.7.2 also shows how to add 10 days to a date.
Listing 5.100 gives a function to add any amount to a date.
Section 6.7 shows examples of using Now() to get the current date.
Note: Recording a macro is usually not a good way to learn Basic programming, because it records ugly dispatcher calls rather than more elegant API code.
Related
I am working with a set of .dta files in Stata, each of which takes some time to create and each of which contains the date of creation in the file name (created at the point of saving using a macro with today's date).
At the moment my do-files identify the relevant .dta file to open based on the today's date macro, but this requires that I run the code to create the .dta files each day.
Is there a way of asking Stata to identify the most recently dated file from a set of files with same filename stem and different dates within a folder (and then open it), once I have run the "cd" command? I had a look on Statalist and SO but couldn't see an answer - any advice gratefully received.
e.g. In the folder, I have files 2020-08-23_datasetA.dta, 2020-08-22_datasetA.dta, 2020-08-22_datasetB.dta etc, and at different points I will want to select the most recently-dated version of A, B, C etc. Hence don't think a simple sort will work as there are datasets A, B, C at play.
(My question is essentially the Stata version of this one about R - Loading files with the most recent date in R)
[edited to clarify that there are multiple datasets, each of which is dated and each of which will need to be opened at different points]
Manifestly two or more files in a particular folder can't have the same name. But we know what you mean.
A utility like fs from SSC will return a list of filenames matching a pattern, alphanumerically sorted. With your dating convention the last named will be the latest as your dates follow (year, month, day) order.
Using another convention for the rest of the filename won't undermine that, but naturally you need to spell out which subset of files is of interest. So a pattern is
. ssc install fs
. fs *datasetA.dta
. local wanted = word(r(files), -1)
where the installation need only take place once. You can circumvent fs by using the calls to official Stata that it uses.
Perhaps you are seeking a program, but it's not clear to me that you need one.
Small detail: You're using the word macro in a way that doesn't match its Stata sense. Stata, for example, is not SAS! The terms code, routine and script are generic and don't conflict with any Stata use. Conversely, code, routine or script may have fixed meanings in other software you use. Either way, Stata questions are best phrased using Stata terms.
Basically I want the document to serve as some kind of journal, to record what I've done every day, so I need to add a date stamp in every entry. It should be like this:
9/14/2015
added a comma to the poem.
9/15/2015
comma deleted.
I know \date{\today} will add the date of the last compilation, but that's not what I want, and the google results are mostly about this (might be I'm search for the wrong key word).
The isodate package provides commands to switch between different date formats. You can use the following command to print a date, see the manual for details.
\printdate{09/14/2015}
The list in your example looks like a revision history, if so, take a look at the vhistory package.
Here is an example:
\documentclass{article}
\usepackage[english,num,USenglish]{isodate}
\dateinputformat{american} % mm/dd/yyyy
\usepackage{vhistory}
\begin{document}
\begin{versionhistory}
\vhEntry{1.0}{\printdate{09/14/2015}}{Olivier Ma}{added a comma to the poem.}
\vhEntry{1.1}{\printdate{09/15/2015}}{Olivier Ma}{comma deleted.}
\end{versionhistory}
\end{document}
How does one get yesterday's date format in a batch file?
I'd like it to look like so: M_d_yyyy
Note that if there's a single digit day and month, I'd like it to be single digits.
Example: 8_5_2013 is August 5th, 2013.
I looked around for a few days but couldn't find a solution.. any lead is much appreciated.
Nothing wrong with free 3rd party executables, but some of us are not allowed to use them on our work machines.
I have written a powerful hybrid JScript/batch utility called getTimestamp.bat that can do nearly any date and time computation on a Windows machine.
There are a great many options for specifying the base date and time, many options for adding positive or negative offsets to the date and time, many options for formatting the result, and an option to capture the result in a variable. Both input and output can be directly expressed as local time, UTC, or any time zone of your choosing. Full documentation is embedded within the script.
The utility is pure script that will run on any modern Windows machine from XP forward - no 3rd party executable required.
Assuming getTimestamp.bat is in your current directory, or better yet, somewhere within your PATH, then the following simple call will define a dt variable containing yesterday's date in M_D_YYYY format:
call getTimestamp -od -1 -f {m}_{d}_{yyyy} -r dt
Note: when I put a date in a file name, I like to use YYYY_MM_DD format because that format will sort chronologically when getting a directory listing.
I think you should get date.exe from UnxUtils.
date.exe --date="1 day ago" "+%-m_%d_%Y"
Download: http://sourceforge.net/projects/unxutils/files/unxutils/current/
Man page: http://www.ss64.com/bash/date.html
#echo off
setlocal
set magic="c:\unx\usr\local\wbin\date.exe" --date="1 day ago" "+%%-m_%%d_%%Y"
for /f %%i in ('%magic%') do set yesterdate=%%i
echo yesterdate = %yesterdate%
If you want to do it with just batch language, you'll end up with nearly 100 lines of incomprehensible batch code. UPDATE: or use dbenham's hybrid batch/JScript solution posted in the answer below, which at least uses sane Windows APIs.
See Also:
How to get current datetime on Windows command line, in a suitable format for using in a filename?
I'm using FileMaker 11 and trying to do a search that will show me only those records that have been modified or added since yesterday. I'm trying to use the Modification_timestamp field (which I think is a built-in FM field) but I can't seem to find the write syntax for the script. ANy help is appreciated.
Thanks,
John
It's not built-in, you have to add timestamp fields and make sure to check the "Modification Date and Time" on the field's auto-enter tab.
The script will be like that:
Enter Find Mode
Set Field[ My Table::Modified On, ">=" & GetAsDate( Get( CurrentDate ) - 1 ) ]
Perform Find
I have what I think is a pretty simple question.
I have a report that is updated daily. A specific range (B5:AC5) from one worksheet needs to be copied to a different worksheet on a daily basis. This doesn't need to be done automatically, I'd just like to add the code for it into a formatting macro I've created.
I have two issues with this:
I want the data to be pasted in the row that corresponds with that specific day. Column A in worksheet "Daily" has the list of working days for that month. So all I need is for the macro to find today's date in Column A in "Daily", and paste b5:AC5 from "Matrix" in b?:ac? in that row on "Daily".
I also need it to be a paste special, with only the values being pasted.
I'm very new to VB, but can usually follow code logic pretty well. Let me know if you need any more information from me. Thank you so much!
Assuming that your range will always be in B5:AC5, here is what I came up with:
Sub FindToday()
Dim FoundDate As Range
Set FoundDate = Worksheets("Daily").Columns("A").Find(DateValue(Now), LookIn:=xlValues, lookat:=xlWhole)
If Not FoundDate Is Nothing Then ' if we don't find the date, simply skip.
Worksheets("Matrix").Range("B5:AC5").Copy
FoundDate.Offset(0, 1).PasteSpecial xlPasteValues, xlPasteSpecialOperationNone, False, False ' You can see that the first argument in PasteSpecial is set to only paste values.
End If
End Sub
I tested this as best I could given your information. I put a set of ascending numbers in the B5:AC5 range, with formulas, put a set of ascending dates for one month in the Daily sheet, and it seems to do what you're looking for.
Hope this helps.