In the XML text below, I want to write an updated script to modify the date part 2013-12- 30T04: 30: 00.000 + 00: 00
with dateadd (min, 2, getdate ())
-
How do I get the format
-
Xml too much print-override "> & Lt; Schedule Definition xmlns: xsd = "http://www.w3.org/2001/XMLSchema" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-Example" & gt; & Lt ; StartDateTime xmlns = "http://schemas.microsoft.com/sqlserver/2006/03/15/reporting/reportingservices"> 2013-12-30T04: 30: 00.000 + 00: 00 gt; WeeksInterval> 1 & lt; / WeeksInterval & gt; & lt; daysOfWeek & gt; & lt; Sunday & gt; True to & lt; / Sunday & gt; Monday & gt; True & lt; / Monday & gt; & Lt; Tuesday and gt; True & lt; / Tuesday & gt; & Lt; Wednesday and gt; True & lt; / Wednesday & gt; & Lt; Thursday and gt; True & lt; / Thursday & gt; & Lt; Friday and gt; True & lt; / Friday & gt; & Lt; Saturdays and gt; True & lt; / Saturday & gt; & Lt; / DaysOfWeek & gt; & Lt; / WeeklyRecurrence & gt; & Lt; / ScheduleDefinition & gt;
this: -
declare @xml Varchar (max) set @ xml = '& lt; Schedule Definition xmlns: xsd = "http://www.w3.org/2001/XMLSchema" xmlns: xsi = "http://www.w3.org/2001/XMLSchema -instance" & gt; & Lt; StartDateTime xmlns = "http://schemas.microsoft.com/sqlserver/2006/03/15/reporting/reportingservices" & gt; 2013-12-30T04: 30: 00.000 + 00: 00 & lt; / Start date & gt; & Lt; Weekly References xmlns = "http://schemas.microsoft.com/sqlserver/2006/03/15/reporting/reportingservices" & gt; & Lt; WeeksInterval & gt; 1 & lt; / WeeksInterval & gt; & Lt; DaysOfWeek & gt; & Lt; Sunday and gt; True & lt; / Sunday & gt; & Lt; Monday and gt; True & lt; / Monday and gt; & Lt; Tuesday and gt; True & lt; / Tuesday & gt; & Lt; Wednesday and gt; True & lt; / Wednesday & gt; & Lt; Thursday and gt; True & lt; / Thursday & gt; & Lt; Friday and gt; True & lt; / Friday & gt; & Lt; Saturdays and gt; True & lt; / Saturday & gt; & Lt; / DaysOfWeek & gt; & Lt; / WeeklyRecurrence & gt; & Lt; / ScheduleDefinition & gt; Select @pos int set @ pos = charindex ('& lt; / startdatetime & gt; , @ Xml), 126) + '+ 00: 00' + substrings (@xml, @ pin, ditlumeth (@xml))
returns: -
& lt; Schedule Definition xmlns: xsd = "http://www.w3.org/2001/XMLSchema" xmlns: xsi = "http://www.w3.org/2001/XMLSchema -instance" & gt; & Lt; StartDateTime xmlns = "http://schemas.microsoft.com/sqlserver/2006/03/15/reporting/reportingservices" & gt; 2014-02-19T21: 27: 36.348 + 00: 00
To find a continuous piece of text ( & startup time
) in your xml charindex ()
It then uses left ()
to cut the start of XML (filing current date). It then uses sysutcdatetime ()
to get the current time of your server in UTC time (so that an offset offset of +00: 00
later To be used) then it uses then change the time format with the style of
126
to change the format required for your XML. It then uses substring ()
and datalength ()
to add the end of your xml (no need to be exact)
Hopefully, it will tell you some idea that you know how to get your XML in place of the date you want it to be replaced.
Comments
Post a Comment