Sample code for 30+ languages & platforms
SQL Server

MIME CurrentDateTime Property

See more MIME Examples

Demonstrates the read-only CurrentDateTime property, which returns the current local date and time formatted as an Internet message date including the numeric UTC offset. The example uses it to populate a Date header field.

Background. Internet message dates follow the RFC 5322 format, for example Fri, 21 Nov 1997 09:55:06 -0600. CurrentDateTime produces a value in that form for use in message headers.

Chilkat SQL Server Downloads

SQL Server
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @sTmp0 nvarchar(4000)
    DECLARE @success int
    SELECT @success = 0

    DECLARE @mime int
    EXEC @hr = sp_OACreate 'Chilkat.Mime', @mime OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    EXEC sp_OAMethod @mime, 'SetBodyFromPlainText', @success OUT, 'Message with a Date header.'
    IF @success = 0
      BEGIN
        EXEC sp_OAGetProperty @mime, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @mime
        RETURN
      END

    --  CurrentDateTime returns the current local date and time formatted as an Internet message date,
    --  including the numeric UTC offset, for example: Fri, 21 Nov 1997 09:55:06 -0600
    DECLARE @now nvarchar(4000)
    EXEC sp_OAGetProperty @mime, 'CurrentDateTime', @now OUT

    PRINT 'Current date/time: ' + @now

    --  It can be used to populate a Date header field.
    EXEC sp_OAMethod @mime, 'SetHeaderField', @success OUT, 'Date', @now

    DECLARE @head nvarchar(4000)
    EXEC sp_OAMethod @mime, 'GetEntireHead', @head OUT
    EXEC sp_OAGetProperty @mime, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 = 0
      BEGIN
        EXEC sp_OAGetProperty @mime, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @mime
        RETURN
      END

    PRINT @head

    EXEC @hr = sp_OADestroy @mime


END
GO