Share via


write a code snippet with todays date

Question

Monday, July 9, 2018 3:58 PM

Hi,

I would like to write a code-snippet that inserts a TODO:

//TODO: 2018-07-09

But I don't know how to insert the formatted date.

iwangoll

All replies (3)

Monday, July 9, 2018 5:47 PM

The code snippets supported in Visual Studio do not support inserting today's date. It is limited to simple replacement and a couple of helper functions.

For more robust support you'd need to look at item templates or a third party tool like CodeRush.

Michael Taylor http://www.michaeltaylorp3.net


Tuesday, July 10, 2018 5:20 AM

Hi iwangoll,

Welcome to the MSDN forum.

What do you mean "TODO"? Please share more detail information about it and that will help us analysis this issue.

Where do you want to insert the formatted date? Like VS, Excel....

Best regards,

Sara

MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com


Wednesday, July 11, 2018 4:39 AM | 1 vote

You can use my Visual Commander extension to quickly insert a comment with the current date. See the following example command:

Sub Run(DTE As DTE2, package As Package) Implements ICommand.Run
    Dim textSelection As EnvDTE.TextSelection
    textSelection = CType(DTE.ActiveDocument.Selection(), EnvDTE.TextSelection)
    textSelection.Text = "//TODO: " + System.DateTime.Now.ToShortDateString()
End Sub

Sergey Vlasov | Vlasov Studio | Visual Studio extensions and tools