Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert current datetime in Visual Studio Snippet

Does anyone know of a way that I can insert the current date & time in a visual studio 2008 snippet? What I want is something like this in the body of my .snippet file...

  <Code Language="csharp">
    <![CDATA[
  // $DateTime$
  // more code here for my snippet...
  </Code>
like image 231
Scott Ivey Avatar asked Jun 22 '09 20:06

Scott Ivey


People also ask

How do I enter a date code?

You must specify the date value in the format M/d/yyyy, for example #5/31/1993# , or yyyy-MM-dd, for example #1993-5-31# . You can use slashes when specifying the year first.


1 Answers

There are no DateTime functions available for snippets but here is a macro that will insert the current DateTime:

Sub PrintDateTime()
    If (Not IsNothing(DTE.ActiveDocument)) Then
        Dim selection As TextSelection = DTE.ActiveDocument.Selection
        selection.Insert(DateTime.Now.ToString())
    End If
End Sub

You can open your macro explorer with Alt + F8 and create a new module and paste the code above inside the module that is generated.

Then create a new keyboard shortcut and bind it to your macro.

like image 69
Andrew Hare Avatar answered Oct 30 '22 18:10

Andrew Hare