w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
Powershell to C# - Get-WMIObject
In order to get at the custom objects being created by the Select-Object cmdlet you can iterate over the Properties member: foreach (var result in results) { foreach ( var property in result.Properties ) { MessageBox.Show( string.Format( "name: {0} | value: {1}", property.Name, property.Value ) ); } }

Categories : C#

SQL Query: Comparing two dates in returned record
Just add a WHERE clause to get started: SELECT tblOne.ServiceID, tblTwo.AccountNbr, tblTwo.AcctName, tblFour.ServiceName, tblOne.Status, tblThree.BeginDate, tblThree.EndDate, tblOne.ServiceYear, tblFive.ServiceBegin, tblFive.ServiceEnd FROM ((tblTwo INNER JOIN tblFour ON tblTwo.AccountNbr=tblFour.AccountNbr) INNER JOIN (tblThree INNER JOIN tblOne ON tblThree.ServiceID=tblOne.ServiceID) ON tblFour.ClientID=tblOne.ClientID) INNER JOIN tblFive ON tblOne.ContractID=tblFive.ContractID WHERE tblThree.EndDate > tblFive.ServiceEnd;

Categories : SQL

converting dates in jquery
I really think you should do this server-side, but if you're intent on using javascript to do this, you could do something like this: Parse the date string into a date object Add a day to it Convert the day back into a formatted date string DEMO $("button").click(function () { var _date = Date.parse($("#day1date").text()); $("#day2date").text(FormattedDate(_date, 1)); $("#day3date").text(FormattedDate(_date, 2)); $("#day4date").text(FormattedDate(_date, 3)); $("#day5date").text(FormattedDate(_date, 4)); $("#day6date").text(FormattedDate(_date, 5)); }); var d_names = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"); var m_names = new Array("January", "February", "March", "April", "May", "June", "July", "August", "

Categories : Jquery

Regarding converting .CSV file dates
Instead of double-clicking on the .csv file try Data > Get External Data - From Text, Import and at Step 3 of 3 format Date to suit. Edit Attempt at clarification I am a little confused by the OP’s comment here (it is not working when coupled with the green tick) and not quite sure whether DMY or MDY is required output but given the source as in ColumnA, then importing with DMY gives ColumnB (after formatting) and with MDY gives ColumnC (after formatting). Both Columns B and C in General format appear as numbers (B5 as 41338 and C5 as 412397 – vice versa in Row6). If say 1/4/13 is April 1st and 1/5/13 is 5th January then I see no solution given the data presently available. The normal problem is where Excel has a default setting such that 6/7/13 converts to July 6th for a dat

Categories : Excel

Trouble converting dates using _.LastWriteTime
Key Issue: Your braces in the Where clause are unbalanced and the pipeline is broken. Additional fixes: Compare year directly since you already have a DateTime object Used formatting for variables in strings, It's just easier when you start dealing with indexes Use -Begin clause on ForEach to initialize counter Anyway, here's a fixed version, converted to a function so you can pick any path, year, and select the log output folder function YearLog { param( [Parameter(Mandatory=$true)][String]$Path, [Parameter(Mandatory=$true)][String]$LogFolder, [Parameter(Mandatory=$true)][Int]$Year ) $log = '{0}FileLog-{1}.txt' -f $LogFolder, $Year if(Test-Path -Path:$log) { Remove-Item -Force -Path:$log } 'Files Found for {0}:' -f $Year |

Categories : Powershell

Converting dates with times like "midnight"
Your best shot is probably the parsedatetime module. Here's your example: >>> import parsedatetime >>> cal = parsedatetime.Calendar() >>> cal.parse('July 1, 2013, midnight') ((2013, 7, 1, 0, 0, 0, 0, 245, 0), 3) cal.parse() returns a tuple of two items. The first is the modified parsedatetime.Calendar object, the second is an integer, as explained in the docstring of the parse method: 0 = not parsed at all 1 = parsed as a C{date} 2 = parsed as a C{time} 3 = parsed as a C{datetime} A few words on strptime: strptime won't be able to understand "midnight", but you can replace it with an actual hour, using something like this: def fix_dt(raw_date): """Replace 'midnight', 'noon', etc.""" return raw_date.replace('midnight', '0').replace('noon', '12')

Categories : Python

Converting dates to Mo/Yr text so I can group by Mo/Yr
Please don't convert dates to strings for this. Use the built in date manipulation functions such as MONTH(TPB105_CHARGE_DETAIL.chg_srv_ts) and YEAR(TPB105_CHARGE_DETAIL.chg_srv_ts) So you might have a query elements like: SELECT YEAR(TPB105_CHARGE_DETAIL.chg_srv_ts) as [Year], MONTH(TPB105_CHARGE_DETAIL.chg_srv_ts) as [Month], SUM(dbo.TPB105_CHARGE_DETAIL.chg_tot_at) as [Charges], (RTRIM(P.lst_nm)) + ', ' + (RTRIM(P.fst_nm)) AS [Provider] FROM [...] GROUP BY YEAR(TPB105_CHARGE_DETAIL.chg_srv_ts), MONTH(TPB105_CHARGE_DETAIL.chg_srv_ts), (RTRIM(P.lst_nm)) + ', ' + (RTRIM(P.fst_nm)) ORDER BY YEAR(TPB105_CHARGE_DETAIL.chg_srv_ts), MONTH(TPB105_CHARGE_DETAIL.chg_srv_ts) This will be much faster, accurate and more efficient than changing the dates to Strings.

Categories : Sql Server

How do I access the object args returned from a .NET event from Powershell
You can use $event in the -Action scriptblock to get access to the event. For example, $watcher = New-Object System.IO.FileSystemWatcher -Property @{Path = 'C:Temp' } $action = { Write-Host (Split-Path -Path $event.sourceEventArgs.FullPath) } Register-ObjectEvent -InputObject $watcher -EventName Created -SourceIdentifier FileCreated -Action $action

Categories : C#

converting all possible string dates to date objects
You could try splitting a string into its component parts(days, months, years) and parsing those individually. ex: String input = 30-08-2011; if (input.indexOf("-") == -1) return; else String day = index.substring(0, selected.indexOf("-")); then the day, can be parsed individually. Then repeat the process for month and year. Then you don't have to worry about the formatting between the components of the date.

Categories : Java

Converting XML data to CSV powershell
Assuming you're after the data in the interfaces node you could do something like this: [xml]$a = @" <SolarWinds_SwitchPortMap Layer2Device="info"> <Interfaces> <Interface ifIndex="data" CollectionTime="data" ConnectorPresent="data" Duplex="data" HardwareType="data" ifAdminStatus="data" ifAdminStatustest="data" ifAlias="data" ifDescr="data" MACAddress="data" MTU="data" ifName="data" ifOperStatus="data" ifSpeed="data" ifType="data" ifTypeName="data" InBitsSec="data" InPktsSec="data" LastChange="data" LastPacketIn="data"

Categories : Xml

Powershell - converting hex from the registry key
Assuming that gp "HKCU:SoftwareMicrosoftWindowsCurrentVersionExplorerComDlg32LastVisitedPidlMRU" gives : PSPath : Microsoft.PowerShell.CoreRegistry::HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionExplorerComDlg32LastVisitedPidlMRU PSParentPath : Microsoft.PowerShell.CoreRegistry::HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionExplorerComDlg32 PSChildName : LastVisitedPidlMRU PSDrive : HKCU PSProvider : Microsoft.PowerShell.CoreRegistry MRUListEx : {14, 0, 0, 0...} 11 : {114, 0, 117, 0...} 9 : {69, 0, 120, 0...} 19 : {83, 0, 107, 0...} 10 : {78, 0, 79, 0...} 17 : {123, 0, 57, 0...} 15 : {115, 0, 108, 0...} 7 : {123, 0, 57, 0...} 4 : {118, 0, 109, 0...} 21 : {109, 0

Categories : Powershell

Converting a .tib image to a vm using powershell
VMware's standalone Converter can convert from some .tib versions and has an API, which I've never used. I'm curious how you're doing this in PowerCLI. edit - The Standalone Converter supports VMware Player and Workstation as destinations. See p20 here. So no, I don't think you need a full-fledged server installation to use this.

Categories : Powershell

Mongoose converting stored UTC dates to local time?
The timestamps are stored timezone agnostically, as a unix timestamp. This timestamp will work across timezones, and node interprets it using your current timezone. You can retrieve the UTC value from the date object using the getUTC* methods such as get getUTCHours()

Categories : Node Js

Converting strings to Calendar Dates and finding the Difference Between them
With the SimpleDateFormat you can parse a String to a Calendar-Object: Calendar cal = Calendar.getInstance(); SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy"); cal.setTime(sdf.parse("Mon Mar 14 16:02:37 GMT 2011"));// all done

Categories : Android

DateTime: Converting 'yW' to earliest and latest possible dates, then BACK TO 'yW'?
I think storing a calendar table in the database makes the most sense here. A calendar table can greatly simplify your code. Queries written against a calendar table are often obviously correct. There's a lot of value in that. One way to answer your failed question with a calendar table is to return the full set of dates. select cal_date from calendar where iso_year = (select iso_year from calendar where cal_date = '2008-12-29') and iso_week = (select iso_week from calendar where cal_date = '2008-12-29') order by cal_date; cal_date -- 2008-12-29 2008-12-30 2008-12-31 2009-01-01 2009-01-02 2009-01-03 2009-01-04 I think that statement is easier to understand, but a JOIN often performs better. select c2.cal_date from calendar c1 inner join calendar c2 on c1.iso_year = c2.iso_

Categories : PHP

converting Object returned by Field.get() to String[] in java reflection
The Object that you get from the call of arrayf.get(inst) is of type Object[], not String[], because Java generics are implemented through type erasure. You can do this: Object[] strings = (Object[])arrayf.get(inst); System.out.println(strings.length); for (int i = 0 ; i != strings.length ; i++) { String s = (String)strings[i]; ... } P.S. I am going to stay away from the discussion on whether it's a good idea to unit test the private details of the implementation.

Categories : Java

Converting JSON returned from ASMX service to list of C# objects
Thanks to Brian Rogers and Tanim Salem (see comments above) I did change the web service so that it not double serialized. I can now simplify the code to something like this: private static JArray ConvertToJsonArray(string json) { var jsonObject = JObject.Parse(json); return (JArray)jsonObject["d"]; } And then convert it to my list of objects using: private static IList<ThirdPartyClaim> ConvertJsonArrayToListOfClaims(JArray jsonArray) { return JsonConvert.DeserializeObject<List<ThirdPartyClaim>>(jsonArray.ToString()); } Any other comments or improvements would be appreciated.

Categories : C#

Powershell: Converting from bytes into gigabytes
Divide the value by 1GB (or 1MB): $Computers = Get-Content "D:DISKSPACE_auditServers.txt" gwmi Win32_LogicalDisk -Computer $Computers -Filter 'DriveType = 3' ` | select SystemName, DeviceID, @{n='FreeSpace';e={[int]($_.FreeSpace/1GB)}}, @{n='Size';e={[int]($_.Size/1GB)}}

Categories : Powershell

Pandas read_csv silently converting and messing up dates and strings?
Not sure the reason for the missing date. I think it's influenced by other rows. For the NULL string problem, keep_default_na can help you to avoid that: df = pd.read_csv('test.csv', sep=',', keep_default_na=False)

Categories : Python

How to troubleshoot "Get-WmiObject : Access is denied."?
Have you considered using Invoke-Command and executing your script2 remotely using PowerShell Remoting? Your remote script can the be executed using alternative credentials, you may have better luck convincing your security team to enable PowerShell Remoting rather than WMI. Your wmi queries when run via invoke-command will be local to the machine so will have a better chance of working, it also avoids the need to read the standard-out buffer. To get you started, try Enter-PSSession as this will enable you to quickly determine how much work is necessary to get PS Remoting working in your environment. In the future you might want to target many computers simultaneously, in which case PS Remoting and Start-Job would be helpful.

Categories : Powershell

get-wmiobject to pull logs using Win32_NTLogEvent
So the answer was that the variable that contained the log information couldn't be combined with other strings in another variable. $FullLog += $server + $log (would not work) $FullLog += $log (would work) Solution? I broke up the information: foreach($server in $servers) { $BeginDate=[System.Management.ManagementDateTimeConverter]::ToDMTFDateTime((get-date).AddDays(-30)) $mylog = Get-WmiObject Win32_NTLogEvent -filter "(logfile='system') AND (EventCode='19') AND (TimeWritten>'$BeginDate')" -computername $server $First = $server + '= [{ "SuccessUpdate":"' $Last = '"}]' $First >> UpdateLog.js $mylog >> UpdateLog.js $Last >> UpdateLog.js write-host $server "logs are uploaded." }

Categories : Powershell

Converting .rtf files to .doc and then .doc back to .rtf in PowerShell (WMF registry fix) - file size optimization
Here is the final working script ( without deleting , I decided I do not need it ) param([string]$rtfpath,[string]$docpath = $rtfpath,[string]$docpath2 = $rtfpath2) $srcfiles = Get-ChildItem $rtfPath -filter "*.rtf" $docfiles = Get-ChildItem $docPath -filter "*.doc" $saveFormat =[Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatDocument"); $saveFormat_back =[Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatRTF"); $word = new-object -comobject word.application $word.Visible = $False function saveas-DOC { $name = $rtf.basename $savepath ="$docpath tf" + $name + ".doc" write-host $name Write-Host $savepath $opendoc = $word.documents.open($rtf.FullName); $opendoc.saveas([ref]$savepath, [ref]$saveFormat); $opendoc.c

Categories : Powershell

LINQ to SQL Data Context - Date Properties - Change DateTImeKind Unspecified Dates to Local Dates
The MSDN article talks about comparing client-side dates. Linq To SQL converts your statement to SQL, where the DateTimeKind property isn't used. You should use DateTimeOffset instead of DateTime. This will allow you to use DateTimeOffset methods in SQL and take advantage of the DATETIMEOFFSET type in SQL Server. LINQ to SQL generates SQL statements. System.DateTime and SQL Server's DATETIME types have no timezone information so it makes no sense to try and take into account the timezone. None of the two values contain any timezone, so how can you make any automatic conversions? The two DateTime values in your question come from two different sources. DateTime.Today comes from your local machine, where the timezone is known, so it's DateTimeKind.Local. The database columns though com

Categories : Dotnet

mySQL Select DISTINCT ips based on dates and return dates
Your query is SELECT COUNT(DISTINCT user_ip) FROM campaigns_visitors WHERE campaign_id = ? GROUP BY date This doesn't return date as you have found. You should have more luck with SELECT COUNT(DISTINCT user_ip), date FROM campaigns_visitors WHERE campaign_id = ? GROUP BY date Others are likely to recomment that you use prepared statements and mysqli routines; I have helpfully translated your query to a format that can be prepared. I trust you can construct the PHP to manipulate the changed statement.

Categories : PHP

updating random dates to a single column (dates repeates)
Don't use a subquery. Just set=your_expression, like in the below example. Oracle optimises the subquery and evaluates it only once, but the expression will be evaluated for each row: create table xyz( abc date ); insert into xyz select sysdate from dual connect by level < 6; select * from xyz; ABC -------- 13/07/17 13/07/17 13/07/17 13/07/17 13/07/17 and now: update xyz set abc = to_date(trunc(dbms_random.value(2456428,2456428+76)), 'J'); select * from xyz; ABC -------- 13/06/14 13/07/23 13/07/26 13/06/24 13/07/10

Categories : SQL

If I have a query that compares two dates in SQL Server, what will happen if one of the dates is null?
always UNKNOWN. NULL value must be treated with IS NULL statement Try this example: declare @d1 datetime declare @d2 datetime set @d1 = GETDATE() select case when @d1 > @d2 then 'OK' else 'KO' end

Categories : SQL

SQL Server: Want to use between clause with dates, but dates in string form (YYYY.MM.DD)
Not good solution, but works (cost much performance). You have formated date in order year, month, day (good order to compare strings, without transformation to datetime), so you can try SELECT * FROM Table WHERE StringDate > '2013.07.10' AND StringDate < '2013.07.14' It returns bad results if there are dates before year 1000 without leading zero ('999.07.14'). But I dont know how it works on big database. SQL Fiddle

Categories : Mysql

Access SQL - given two dates, return the dates of the previous period
Here's a little cleaner SQL. It assumes that the StartDate is always the first of the month. This calculates the period length, and returns the same length ending the day before the current period starts. SELECT QueryDates.StartDate, QueryDates.EndDate, Dateadd("m", Datediff("m", [EndDate] + 1, [StartDate]), [StartDate]) AS StartDatePrevious, [StartDate] - 1 AS EndDatePrevious FROM QueryDates;

Categories : SQL

How does excel convert Julian dates to calender dates?
41348 is not julian date. Excel needs to use a formula to convert a julian date to a proper date. 183349 is an example of a julian date. 41348 is simply the number of days passed after 01/01/1900. You can add those number of days to 01/01/1900, if I recall correctly, in SQL server to get the desired results. EDIT: Yup, use DATEADD. Add a column with 01/01/1900 UPDATE Table SET NewDate = DATEADD(Days, RawDate-2, '01/01/1900') You need to remove 1 from the RawDate since 1 corresponds to 01/01/1900 and another 1 apparently I'm not sure where, but investigating. On my SQL Server2008R2, apparently it considers 1900 to be a non-leap year. There goes the additional 1 to remove!

Categories : Sql Server

Convert text dates to dates and then keeping the NA values
The problem is that pd.NaT.date() will not raise an error, it will return datetime.date(1, 255, 255), so the part of your code where you catch an exception will never be reached. You'll have to check if the value is pd.NaT and in that case return 'NA'. In all other cases you can safely return obj.date() since the column has datetime64 dtype. def try_convert(obj): if obj is pd.NaT: return 'NA' else: return obj.date() n [17]: s.apply(try_convert) Out[17]: 0 2012-06-28 1 2013-05-21 2 2011-10-14 3 2011-11-11 4 2013-02-07 5 2013-01-02 6 2013-06-24 7 2013-07-15 8 2011-11-04 9 2013-04-29 10 2013-06-24 11 2012-10-22 12 NA 13 NA 14 2011-12-13 Name: 1_2, dtype: object

Categories : Python

In C#, parse out biweekly sets of dates from a collection of dates?
You'll need to figure out the week number for the date in question. For example: var dt = new DateTime(...); // your datetime var cal = new System.Globalization.GregorianCalendar(); var weekNum = cal.GetWeekOfYear(dt, CalendarWeekRule.FirstDay, DayOfWeek.Sunday); There are different strategies for counting weeks of the year, which you specify with a CalendarWeekRule and corresponding DayOfWeek for the starting day of the week. You can read more here. Once you have a week number, you can do some math to make it "bi-weekly": int biweeklyKey = weekNum % 2; The value will be either 0 or 1, which you can use as a key in your algorithm.

Categories : C#

Incorrect date returned when converting from java.util.date to java.sql.date
This may help you Calendar cal = Calendar.getInstance(); DateFormat df=new SimpleDateFormat("dd/mm/yyyy"); String dateStr="20/04/1961"; Date date = df.parse(dateStr); cal.setTime(date); Date sqlDate = new java.sql.Date(cal.getTime().getTime()); System.out.println("utilDate:" + df.format(date)); System.out.println("sqlDate:" + df.format(sqlDate));

Categories : Java

Using mysql to query dates that fall between 2 other dates
Assuming start_date and end_date are DATETIME, and you want to compare the date AND time components, you could do something like this: SELECT a.* FROM atable a WHERE a.start_date >= NOW() AND a.end_date <= NOW() + INTERVAL 30 DAYS If start_date and end_date are DATE (rather than DATETIME), you probably only want to compare the DATE portion (without regard to a time component) SELECT a.* FROM atable a WHERE a.start_date >= DATE(NOW()) AND a.end_date <= DATE(NOW()) + INTERVAL 30 DAYS You may actually want a less than comparison (rather than less than or equal to) on the end date. You need to determine what results you want on that edge case. And the interval may need to be specified as 29 days, depending on how you define "the next 30 days". Q: Wh

Categories : Mysql

Construct an array of dates between start and end dates. (d3.js)
To do it with d3: var dateArray = d3.time.scale() .domain([new Date(2013, 2, 28), new Date(2013, 3, 2)]) .ticks(d3.time.days, 1) Online demo: http://jsfiddle.net/aczuV/1/

Categories : Javascript

Sorting Dates Does Not Return Sorted Dates
.sort() will sort in "dictionary" order, not numeric or date/time order. If the values aren't strings they'll get a default string conversion which for dates does not give you something useful to sort on. But you can supply a custom sort callback that knows how to sort dates: .sort(function(a,b) { return a.getTime() - b.getTime(); }); Demo: http://jsfiddle.net/TUAz9/

Categories : Javascript

Compare Two Dates with Two Other Dates in SqlServer 2008
I think you might be looking for something like (dbo.ArrangementPromotion.ActiveFromDate BETWEEN '2013-08-01' AND '2013-08-14') OR (dbo.ArrangementPromotion.ActiveToDate BETWEEN '2013-08-01' AND '2013-08-14' ) OR ('2013-08-01' BETWEEN dbo.ArrangementPromotion.ActiveFromDate AND dbo.ArrangementPromotion.ActiveToDate) OR ('2013-08-14' BETWEEN dbo.ArrangementPromotion.ActiveFromDate AND dbo.ArrangementPromotion.ActiveToDate) Where '2013-08-01' should be @ActiveFrom and '2013-08-14' @ActiveTo

Categories : Asp Net

Counting dates that fall between two dates in the same column
SQL Fiddle select t1.id, level, count(t2.id) from ( select id, level, tsrange( "time", lead("time", 1, 'infinity') over( partition by id order by level ), '[)' ) as time_range from t1 ) t1 left join t2 on t1.id = t2.id and t1.time_range @> t2."time" group by t1.id, level order by t1.id, level The solution starts creating a range of timestamps using the lead window function. Notice the [) parameter to the tsrange constructor. It means to include the lower and exclude the upper bound. Then it joins the two tables with the @> range operator. It means the range includes the element. It is necessary to left join t1 to have the zero counts.

Categories : Amazon

Getting results between two dates in PostgreSQL including those two dates
use end_date + 1 day and < instead of <= SELECT * FROM tbl WHERE start_date < '2012-04-13'::timestamp AND end_date >= '2012-01-01'::timestamp; I think it should perform better than casting data in you table to date

Categories : Ruby On Rails

Why would installing Azure SDK 2.1 or powershell 3 on the build server break some of our tests which run in powershell?
Have you tried passing a fully qualified path to startInfo.FileName instead of just Powershell.exe incase there's a problem with %PATH% since the update Complete total guess, but any chance your running into FileSystemRedirector 32 vs. 64 issues as seen in this answer - Process.Start(): The system cannot find the file specified, but my file path seems to be legit

Categories : Powershell

PowerShell Community Extensions not Recognized by TeamCity PowerShell Runner
Do you import the PSCX module in your script? PowerShell v3 will cache the module info after you have done this once so you don't need to import it again. However if TeamCity is running the 64-bit console and you normally run the 32-bit console, then the 64-bit console wouldn't have PSCX commands in the command cache. Anyway, it is a good practice to have your scripts explicitly require the modules it depends upon e.g. #requires -Modules Pscx

Categories : Powershell



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.