w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
MySQL select date range from table where there's only one column for date
SELECT emp_name,min(startdate) as startdate,max(ldate) as enddate,team FROM ( SELECT emp_name,startdate ,team, @n:=if(@lastteam=team,@n,@n+1) rank, @l:=if(@enddate=startdate,startdate,@enddate) ldate, @lastteam:=team, @enddate:=startdate FROM t, (SELECT @n := 0,@lastteam:='',@enddate:='') n ORDER BY startdate desc ) m GROUP BY rank SQL FIDDLE here: http://www.sqlfiddle.com/#!2/860fd/20

Categories : Mysql

fill a range on times in Column B for each date in Column A
This formula may work for you. It will check to see if the date in the previous row is equal to the date in the current row; if it is not, then it will set the time as your start time (13:00). If it is, then it adds 15 minutes to the time above the current row. =IF(A2<>A1,TIME(13,0,0),B1+TIME(0,15,0)) This formula can be placed next to all of your dates (in the time column)

Categories : Excel

Taking sum of column based on date range in T-Sql
I think that there might be a better solution but this should work: where YEAR(VoucherDt) = YEAR(CURRENT_TIMESTAMP) and MONTH(VoucherDt) = MONTH(CURRENT_TIMESTAMP) and DAY(VoucherDt) <= DAY(CURRENT_TIMESTAMP)

Categories : SQL

How can I create a Date Range from a single column?
You need an aggregation to get the minimum and maximum values for each email, before doing datediff(): SELECT [Email Address], DATEDIFF(day, min([Transaction Date]), max([Transaction Date])) AS 'dateDiff' FROM [DB].[TABLE] GROUP BY [Email Address] order by 2 desc;

Categories : SQL

executing perl script from python
Your Perl script is wrong: You read the path from STDIN, not from the command line arguments. You do not remove the newline after reading a line. You would be looking for "foo " instead of "foo". You have no error checking whatsoever. You do not load the Data::Dumper module. And are you sure that you really want to execute the file at $path as Perl code? Cleaned up, I'd write the Perl script as perl -MData::Dumper -do $ARGV[0];' -e'print Dumper \%some_global' input-file.pl >output Or as use strict; use warnings; use Data::Dumper do $ARGV[0]; open my $fh, ">", "output" or die "Can't open output: $!"; print { $fh } Dumper \%some_global; If you really want the filename from STDIN: use strict; use warnings; use Data::Dumper; chomp(my $path = <STDIN>); do $p

Categories : Python

Python script executing SQL on Synology NAS
you can install a mysql connector from official mysql source : http://dev.mysql.com/doc/connector-python/en/index.html. bye

Categories : Python

TSQL - date range calculation with different records in column
Try this : SQL Fiddle Query: with demo_cte as ( select DATEPART(wk,getdate()) CW,DATEPART(MM,getdate()) MO , GETDATE() cur_date, DATEADD(MM,-2,getdate()) end_date union all select DATEPART(wk,cur_date-7) CW,DATEPART(MM,cur_date-7) MO , cur_date -7 cur_date, end_date from demo_cte where cur_date>end_date ) select * from demo_cte Results: | CW | MO | CUR_DATE | END_DATE | ------------------------------------------------------------------------- | 24 | 6 | June, 13 2013 12:18:43+0000 | April, 13 2013 12:18:43+0000 | | 23 | 6 | June, 06 2013 12:18:43+0000 | April, 13 2013 12:18:43+0000 | | 22 | 5 | May, 30 2013 12:18:43+0000 | April, 13 2013 12:18:43+0000 | | 21 | 5 | May, 23 2013 12:18:43+0000 | April, 13 2013 12:18:43+

Categories : SQL

import module without executing whole script python
If the problem is arising from executing the LogInPage during the import... you can protect the code in LogInPage. Keep those codes in if __name__ == '__main__: block from being executed by import statements.

Categories : Python

MySQL: Growth in Column Value for Given Foreign Key and Specific Date Range
If the pins column is a daily delta, the net change in the number of pins added/removed on a given date, then: SELECT @StartDate = DATE_FORMAT(NOW(),'%Y-%m-%d') + INTERVAL -1 DAY SELECT @EndDate = DATE_FORMAT(NOW(),'%Y-%m-%d') SELECT t.page_id , SUM(t.pins) AS `Pins_DayOverDay` FROM mytable t WHERE t.date >= @StartDate AND t.date <= @EndDate GROUP BY t.page_id ORDER BY `Pins_DayOverDay` DESC LIMIT 1 If the pins column is cumulative and contains a total count of the number of effective pins (pins done on previous days plus pins added/removed today), assuming that (page_id,date) is unique: SELECT t.page_id , (t.pins - s.pins) AS `Pins_DayOverDay` FROM mytable t JOIN mytable s ON s.page_id = t.page_id WHERE t.date = @EndDate AND s.date = @Start

Categories : Mysql

How can I find the currently executing script file and path in python?
In case __file__ is not set, you can get the directory via import sys, os script = os.path.abspath(sys.argv[0] or 'unknown script') directory = os.path.dirname(script))

Categories : PHP

Launch Python debugger while simultaneously executing module as script
After experimenting with this for quite some time, it turns out that this approach actually works: python -c "import runpy; import pdb; pdb.runcall(runpy.run_module, 'somepackage.somemodule', run_name='__main__')" For some reason, the use of pdb.runcall over pdb.run is important.

Categories : Python

TypeError: unsupported operand type(s) for +: 'NoneType' and 'str' in executing python script
I see you've cranked out a lot of code, however, it's littered with syntax errors. I'd recommend you try writing smaller chunks at a time, getting each step working as you plug along. First, your while loop is infinte. Second, if you want to use parenthesis with print (which I recommend), for Python 2.x, use this at the top of your files: from future import print_function Third, you should always use os.path for portable filesystem path manipulations. What your error means is that, somewhere, you're trying to add a None type with a string. That's not possible, of course, so Python throws an exception. What you need to do, is to figure out why whatever you're adding is None, and fix that ;) Hope that helps!

Categories : Python

Relative paths break when executing Python script from Windows batch?
Yes, that is logical. The files are relative to your working directory. You change that by running the script from a different directory. What you could do is take the directory of the script you are running at run time and build from that. import os def read_file(filename): #get the directory of the current running script. "__file__" is its full path path, fl = os.path.split(os.path.realpath(__file__)) #use path to create the fully classified path to your data full_path = os.path.join(path, filename) with open(full_path, "r") as file: #etc

Categories : Python

find unicode range through python script
Maybe you can use the ord() function. It returns the characters numeric value and you can decide what to do with the char. Example: devanagari_letter_a = unichr(2309) devanagari_letter_aa = unichr(2310) print devanagari_letter_a.encode('utf-8'), 'value:', ord(devanagari_letter_a) print devanagari_letter_aa.encode('utf-8'), 'value:', ord(devanagari_letter_aa) Output: अ value: 2309 आ value: 2310

Categories : Python

python: query a DATETIME field in a sqlite db for a date range
You can do a query like this: SELECT * FROM Table where date >= date('now', '-60 day'); EDIT: Based on your actual query: select <field1>, <field2>, count(1) as num FROM Table where date >= date('now', '-60 day'); group by <field1>, <field2>; SELECT DISTINCT is unnecessary when you are using GROUP BY.

Categories : Python

Python - IndexError: list index out of range - but only in one column of data
The parser might just use the space as a separator - thus the space between both first and second, and the second and third column could be seen as separating the first cell from a empty cell in the second column. To get rid of the error, just check for the sublist length! (And please use a for loop...) for row in AudioAngle: print(row[0]) print(row[1]) if len(row) >= 3: print(row[2])

Categories : Python

jquery code not executing from script, but executing from dev panel
The click handler you've shown is bound to any ".maintypedata img" elements that exist when that code runs. But, the img elements in question are appended to the document dynamically after the "Bamboo" option is clicked. So you need to either run that .click() code after the elements are appended (which is what you were doing by running it from the console) or change it to work as a delegated event handler: $(".maintypedata").on("click", "img", function() { console.log("test"); if(open == false) { var src = $(this).attr("src"); $(".popup").html("<img src='"+src+"'/>"); open = true; $(this).addClass("selected"); $(".popup").slideFadeToggle(function() { });

Categories : Javascript

How to check if selected date range is between another date range
This query should do it: SELECT * FROM lifecycles WHERE str_to_date(life_start_date, '%m/%d/%Y') <= '2014-01-01' AND str_to_date(life_end_date, '%m/%d/%Y') >= '2013-08-01'; Which basically means life hasn't started before the end of the range you are looking for, and life didn't end before the range start. Since you keep dates in VARCHAR format, you need to use str_to_date function, which is bad since MySQL won't be able to utilize any possible indexes you have on start_date or end_date columns.

Categories : Mysql

Determine if date range fulls within another date range
you can check if the row exists with same range through sql select if(count(*) >0,'conflicts', 'does not conflict') from yourTable where ($startTime between time_from and time_till) or ($endTime between time_from and time_till) if any of the input date lies the existing date range, it will show conflicts otherwise it will result does not conflict

Categories : PHP

Query to return rows in date range but return only max value of column
Using the row_number() function to rank the rows select product, price, version from ( select *, row_number() over (partition by product order by version desc) rn from yourtable where @dategiven between startdate and enddate ) v where rn = 1

Categories : SQL

Python thread timer, not executing or executing instantly
You lost all the indentation in your code snippet, so it's hard to be sure what you did. The most obvious problem is responseTimer.start. That merely retrieves the start method of your responseTimer object. You need to call that method to start the timer; i.e., do responseTimer.start(). Then it will produce the output you expected, with a delay of about 2 seconds before the final "timeout!" is printed.

Categories : Python

Select the lowest date from a range and exclude another range
You could use the ROW_NUMBER() function to rank the records based on RecordId and mDate, then limit the results to where the first occurance is between your specified dates. WITH data AS ( SELECT a.relatedId, a.mdate, rn = ROW_NUMBER() OVER(PARTITION BY a.RecordId ORDER BY a.mdate) FROM audit a WHERE a.status in ('A','B','C') AND type = 'type1' ) SELECT r.source, [Count] = COUNT(*) FROM data d LEFT JOIN related r ON d.relatedId = r.id WHERE d.rn = 1 AND d.mdate >= '2013-04-04 00:00:00.000' AND d.mdate < '2013-04-05 00:00:00.000' GROUP BY r.source; I am not sure this will perform any better than your current solution, but will solve the problem of relying on chronological inserts. If chronological inserts are not a prob

Categories : SQL

Executing a script within a script but continuing on error(s) and saving them to file
errors = open('errors.txt', 'w') try: execfile("script.py") except Exception as e: errors.write(e) try: execfile("other.py") except Exception as e: errors.write(e) errors.close()

Categories : Python

Excel VBA - How to compare today's date in one column with a future date in a second column
First of all, you need to understand how does VBA "understands" a date. Excel, Access, VBA and many MS products store dates as a double precision number; the integer part of the number is the date (number of days counted since January 1st, 1900), and the decimal portion of the number is the time (fraction of day). This makes it easy to compare two dates: You can compare, add or substract dates just as if you were using numbers. So, if t0 and t1 are two dates (t1 >= t0), then the expression t1 - t0 will give you the difference of days. Now... how yo count the "business days" between two dates? The format() function in VBA can help you. You can use this function to return the "day-of-week" number. Check the online help of the function: http://msdn.microsoft.com/en-us/library/office/gg2

Categories : Excel

JavaScript date range between date range
In your example, the new dates are both outside the range. If you want to check if there is any overlap between the date ranges, use: return (endD >= startdate && startD <= enddate);

Categories : Javascript

column replacing with existing column while executing stored procedure
You missed the ','. Try this : BEGIN DECLARE @cols AS NVARCHAR(MAX) ,@query AS NVARCHAR(MAX) SELECT @cols = STUFF(( SELECT DISTINCT ',' + QUOTENAME(Vtype) FROM VType_tbl FOR XML PATH (''), TYPE).value('.', 'NVARCHAR(MAX)'), 1, 1, '') SET @query = 'SELECT LocName, ' + @cols + ' from ( select l.LocName, Vtype from Transaction_tbl t inner join VType_tbl v on t.vtid = v.vtid join dbo.Location_tbl l on t.locid=l.Locid where dtime between ''' + @startdate + ''' and ''' + @enddate + ''' and Status >= 5 ) d pivot ( count(Vtype) for Vtype in (' + @cols + ') ) p ' EXECUTE (@query) END

Categories : SQL

Joining the correct budget date range fields based on the date of a service
you can use the BETWEEN clause on a.ID=b.ID AND DOSStart BETWEEN Start_DT AND End_DT . try this: CREATE TABLE #Service_Budget( ID int, SERV_Type int, Start_DT datetime, End_DT datetime, Budget int, NUMBER_OF_MONTHS_OF_SERVICES int ); INSERT INTO #Service_Budget VALUES (13946, 5, '4/2/2012', '4/2/2013', 622.4, 12), (13946, 5, '4/2/2013', '4/2/2014', 788.4, 12) CREATE TABLE #Service_Visits( ID int, Service_Type int, DOSStart datetime, BillableUnits int, RATE_AMOUNT int ); INSERT INTO #Service_Visits VALUES (13946, 5, '4/15/2013', 3,75.5) SELECT a.ID, a.Service_Type, a.DOSStart, MONTH(a.DOSStart) AS Month, YEAR(a.DOSStart) AS Year, MONTH(b.START_DT) AS Start_Month, YEAR(b.START_DT) AS Start_Year, b.Start_DT, b.End_DT,

Categories : SQL

Combinations of date ranges that covers all days of input date range
I added a couple more data items to make it more interesting: $start = strtotime('2013/01/10'); $end = strtotime('2013/01/25'); $range[0]['start'] = "2013/01/08"; $range[0]['end'] = "2013/01/10"; $range[1]['start'] = "2013/01/09"; $range[1]['end'] = "2013/01/15"; $range[2]['start'] = "2013/01/10"; $range[2]['end'] = "2013/01/20"; $range[3]['start'] = "2013/01/18"; $range[3]['end'] = "2013/01/27"; $range[4]['start'] = "2013/01/14"; $range[4]['end'] = "2013/01/19"; $range[5]['start'] = "2013/01/19"; $range[5]['end'] = "2013/01/25"; $range[6]['start'] = "2013/01/14"; $range[6]['end'] = "2013/01/26"; $range[7]['start'] = "2013/01/10"; $range[7]['end'] = "2013/01/26"; $range[8]['start'] = "2013/01/9"; $range[8]['end'] = "2013/01/15"; $range[9]['start'] = "2013/01/13"; $range[9]['end'] = "2013/

Categories : PHP

jQueryUI datepicker formatted date range clearing its partner on new date
This works fine for me: From date: $( "#datepicker_start" ).datepicker({ onClose: function( selectedDate ) { $( "#datepicker_end" ).datepicker( "option", "maxDate", selectedDate ); } }); To date: $( "#datepicker_end" ).datepicker({ onClose: function( selectedDate ) { $( "#datepicker_start" ).datepicker( "option", "maxDate", selectedDate ); } });

Categories : Jquery

Find current date in a date range string for form select
I have a very elegant solution for you, which is very clean to understand, but my advice is to use Moment.js as a plugin helper for handle the dates, and a simple plugin which is called moment-range.js to calculate the ranges for you. With these plugins, your code could be stripped down to this: // Coming from json or whatever... var dates = ["07.10.2013-01.11.2013", "09.09.2013-04.10.2013", "12.08.2013-06.09.2013", "15.07.2013-09.08.2013", "17.06.2013-12.07.2013", "20.05.2013-14.06.2013", "22.04.2013-17.05.2013", "25.03.2013-19.04.2013"]; $(dates).map(function(i,item) { // Split the dates var datesSplit = item.split("-"); // Define dates and range var start = moment(datesSplit[0], "DD.MM.YYYY"); var end = moment(datesSplit[1], "DD.MM.YYYY"); var today = moment(

Categories : Javascript

SqlLite select query for between date range with date format mm-dd-YYYY
The American date format is inherently unsortable because units are not arranged in consistently increasing or consistently decreasing order. An ISO (Japanese) style date, however, can be sorted alphabetically making it the most superior of human-readable (and computer sortable) forms. In the absence of a practical date format you have to convert that text string into something sortable, e.g. a Japanese form text string, or an integer. For SQLite see Date and Time Functions. For parsing date strings in SQLite see this StackOverflow answer.

Categories : Sqlite

Executing a PHP script containing a path to another PHP script in another location
The include path only applies if you give a relative pathname. You gave an absolute pathname (starts with "/"), so PHP was looking for the file in /scripts (that is, at the root directory of your computer). You have two options: Use a relative pathname, like "./scripts/checkcmtimg.php" or simply "scripts/checkcmtimg.php". This will involve the include_path, searching each directory in the include path for that relative path. Use an absolute pathname, like "/Users/peter/Documents/firm/worlddiki/na/ejs/scripts/checkcmtimg.php". This will not use the include_path, it will search for the file in just the one location.

Categories : PHP

Need to sort by Date then Hour, then output Date, text Day of week , range of hours SQL Server 2008 R2
This should solve the problem: ; With Streamlined as ( SELECT DATEADD(hour,DATEDIFF(hour,'20010101',adm_ts),'20010101') as RoundedTime, vst_ext_id from TPM300_PAT_VISIT where adm_srv_cd='22126' and adm_ts >= '20130701' and adm_ts < '20130801' ) Select CONVERT(date,RoundedTime) as [Date], DATEPART(weekday,RoundedTime) as [Day of Week], DATEPART(hour,RoundedTime) as [Hour], count(vst_ext_id) as [Total Visits] From Streamlined Group by RoundedTime Order by CONVERT(date,RoundedTime), DATEPART(hour,RoundedTime) In the CTE (Streamlined)'s select list, we floor each adm_ts value down to the nearest hour using DATEADD/DATEDIFF. This makes the subsequent grouping easier to specify. We also s

Categories : Sql Server

Filter by date range when the date is split into multiple fields
Do you have access to modify the DB schema? If so you could consider a 'generated column' for the date : https://www.ibm.com/developerworks/community/blogs/SQLTips4DB2LUW/entry/expression_generated_columns?lang=en

Categories : SQL

Date Range Picker how to fire an event on entering a date
this section is the callback function: function(start, end) { $('#dateRange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY')); } you can add any code you want in this function to execute when a user selects a date. you could even define a callback function yourself and pass it to the daterange picker method. example: function myCallBack(start, end) { $('#dateRange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY')); alert('hello world'); //etc, your code here } // attach daterangepicker plugin $('#dateRange').daterangepicker(options, myCallback); you also could even define your own custom event handler and trigger it in the callback as well. example $(document).on('myCustomEvent', function () { // your code h

Categories : Javascript

Invoke python script from another python script and set execution directory of the executed script
You could use cwd parameter, to run scriptB in its directory: import os from subprocess import check_call check_call([scriptB], cwd=os.path.dirname(scriptB))

Categories : Python

Group by historical date for each date in the provided range
Maybe consider this example... SELECT * FROM ints; +---+ | i | +---+ | 0 | | 1 | | 2 | | 3 | | 4 | | 5 | | 6 | | 7 | | 8 | | 9 | +---+ SELECT x.i, SUM(y.i) running FROM ints x JOIN ints y ON y.i <= x.i GROUP BY i; +---+---------+ | i | running | +---+---------+ | 0 | 0 | | 1 | 1 | | 2 | 3 | | 3 | 6 | | 4 | 10 | | 5 | 15 | | 6 | 21 | | 7 | 28 | | 8 | 36 | | 9 | 45 | +---+---------+

Categories : Mysql

mysql date range ignores end date in result
2013-07-31 12:00:00 is neither smaller nor exactly equal to 2013-07-31. To fix it either you strip off the time part from your datetime column using date() select * from employee where date(admissiondate) between '2013-01-01' and '2013-07-31' But that won't make use of indexes. Or add a time part like this select * from employee where admissiondate >= '2013-01-01' and admissiondate <= '2013-07-31 23:59:59' SQLFiddle demo

Categories : Mysql

to select latest date and last but-one date from date column in SQL Server 2005
Simple use of ROW_NUMBER: ;WITH OrderedRows as ( SELECT ID,Date,ROW_NUMBER() OVER (PARTITION BY ID ORDER BY Date desc) rn from Table ) select * from OrderedRows where rn <=2

Categories : SQL

Python - Pandas: Get a group of mean values of a daily range in a longer range period
import datetime as DT import numpy as np import pandas as pd np.random.seed(2013) N = 10**4 df = pd.DataFrame( np.cumsum(np.random.random(N) - 0.5), index=pd.date_range('2010-8-31', freq='10T', periods=N)) # 0 # 2010-08-31 00:00:00 0.175448 # 2010-08-31 00:10:00 0.631796 # 2010-08-31 00:20:00 0.399373 # 2010-08-31 00:30:00 0.499184 # 2010-08-31 00:40:00 0.631005 # ... # 2010-11-08 09:50:00 -3.474801 # 2010-11-08 10:00:00 -3.172819 # 2010-11-08 10:10:00 -2.988451 # 2010-11-08 10:20:00 -3.101262 # 2010-11-08 10:30:00 -3.477685 eight_to_five = df.ix[df.index.indexer_between_time(DT.time(8), DT.time(17))] # 0 # 2010-08-31 08:00:00 1.440543 # 2010-08-31 08:10:00 1.450957 # 2010-08-31 08:20:00 1.746454 # 2010-08-31 08:30:0

Categories : Python



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