I built a function that returns a list of date and time - ['2/12/2018', '15: 55 ']
Or in different order ['15: 55 ',' 2/12/2018 ']
How can I build a code that will always take only the date?
Looks like you return them as a String. In that case what about this:
list_of_lists = [["2/12/2018", "15:55"], ["23/12/2018", "22:32"]]
for list in list_of_lists:
for x in list:
if(x.find(":") != -1):
print(x)
That should do it.
Related
Performing PostgreSQL query
when searching from two lists for matches in a database i receive the following error:
ProgrammingError: operator does not exist: character varying ~~ text[]
LINE 1: ...FROM public."Phosphosite_table" WHERE "GENE_NAME" LIKE ARRAY...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
my code is the following:
start = time.time()
input_file = "az20.tsv"
names = []
residuelist = []
kinase = []
fclist = []
with open(input_file, "r") as data:
data = csv.reader(data, delimiter='\t')
next(data, None)
for row in data:
data = row[0:6]
if "(" in data[0]:
name = data[0].split("(")[0]
residue1 = data[0].split("(")[1]
residue = residue1.split(")")[0]
fc = data[3]
else:
pass
if "_" in name:
name = name.split("_")[0]
if residue != "None":
names.append(str(name))
residuelist.append(str(residue))
fclist.append(fc)
genename = names
location = residuelist
connection = pg.connect(HAHAHA)
cur = connection.cursor()
cur.execute('SELECT "KINASE_NAME" FROM public."Phosphosite_table" WHERE "GENE_NAME" LIKE %s and "RESIDUE" LIKE %s',\
(genename, location))
query = cur.fetchall()
print query
connection.close()
end = time.time()
print str((end - start)/60) + " Minutes"
I have done some research and it appears that PostgreSQL does not perform any typecasting. However, I thought it would be a comparison of a string against a string, which, I changed before appending to my list. Does anyone have any advice?
Connor
However, I thought it would be a comparison of a string against a string
The part character varying ~~ text[] of the error message tells you, that you are comparing a string ("character varying") with an array ("text[]").
If you want to compare a single value with all elements of an array you need to use the ANY operator:
WHERE "GENE_NAME" LIKE any(%s)
assuming that %s is passed as native Postgres array from your code (which seems to be the case given the error message).
i have a string "October.29.2009 11:00 a.m."
I want to write a generic code that will replace the time with blank space.
I have tried the below code :
{
val date="October.29.2009 11:00 a.m." //time may be any value
date.replace("a.m.","").replace("p.m.","")
}
Above code can replace am and pm only. I need to replace time also.
Have you tried splitting the string. Use this:
date.split(" ")
The first element of the array returned will give you the date without time.
you can use regex like that
^([0-9]|0[0-9]|1[0-9]|2[0-3]):[0-5][0-9]$
Is your time always with leading zeros?
07:08
Then use
myString.reverse.substring(countYourCharsAndDigits).reverse
Or use a regex that matches the first part, that you are interestet in, and the rest and write it like
def dateExtractor(date:String) = {
val MatchExpression = "('hereTheRegExForTheInterestingPart')('regExForRest)".r
val MatchExpression(myNewString,rest) = date
myNewString
}
the ( and ) is needed for the matchen the ' not
I am new to Access 2010 VBA but have solid SQL background. I am trying to open/browse a form from a toogle button based on complex filter.
The form is called: FormSuivi
In SQL, the filter would be like this:
WHERE Randomise = 'Y' AND ActualSxDate is not null
AND datediff('d', Date(),ActualSxDate) > 140 AND DCD = 0;
In this Accessdatabase, the following field's types are:
Randomise: text
ActualSxDate: Date
DCD: Yes/no -> integer (-1/0)
For now, all I managed to do is to implement one condition at a time:
Private Sub Toggle25_Click()
DoCmd.BrowseTo acBrowseToForm, "FormSuivi", , "Randomise = """ & "Y" & """"
End Sub
How can all the conditions listed in SQL be squeezed into a VBA command line?
The parameter WhereCondition can be a full WHERE string, without the WHERE keyword. Including ANDs, parentheses, etc.
Single quotes ' help to keep the string readable (as opposed to """ constructs).
Variables need to be concatenated, e.g.
Dim S As String
S = "Randomise = '" & strRandomise & "' AND ActualSxDate is not null " & _
"AND datediff('d', Date(),ActualSxDate) > 140 AND DCD = " & bDCD
DoCmd.BrowseTo acBrowseToForm, "FormSuivi", , S
Question:
I used the custom date format(e.g., 4/22 11:00), and display these dates on the horizontal axis, however I want to split the date format( 4/22 11:00) into two lines,for instance,
4/22
11:00
Why do I want this
Date( 4/22 ) and time(11:00) are displayed at the distinct lines, which can easily differentiate date from time.
What did I try
I found an item "Wrap" in "Alignment", but it can't work.
Better late than ever, if you're still interested, there's a way.
You need to create a new calculated field, to generate the labels as you wish. If the field you're working if is called Date (for instance), you should do:
STR(DAY([Date])) + '/' + STR(MONTH([Date])) + '/' + STR(YEAR([Date]))
+
'
'
+
IF LEN(STR(DATEPART('hour',[Date]))) == 1
THEN '0' + STR(DATEPART('hour',[Date]))
ELSE STR(DATEPART('hour',[Date]))
END
+
':'
+
IF LEN(STR(DATEPART('minute',[Date]))) == 1
THEN '0' + STR(DATEPART('minute',[Date]))
ELSE STR(DATEPART('minute',[Date]))
END
First line is just to get the date on a d/m/y format. Then the trick is to add + '' separated by blank space (tried \n, but it prints "\n" instead of breaking the line)
The second part is to generate the hh:mm (you can use the same logic to get a dd/mm/yyyy format for the date). Basically it adds a zero if the hour or minute is a one digit number.
I have an xml database that contains films, for example:
<film id="5">
<title>The Avengers</title>
<date>2012-09-24</date>
<family>Comics</family>
</film>
From a Perl script I want to find film by date.
If I search films of an exacly year, for example:
my $query = "//collection/film[date = 2012]";
it works exactly and return all films of 2012 year, but if I search all film before a year, it didn't work, for example:
my $query = "//collection/film[date < 2012]";
it returns all film..
Well, as usual, there's more than one way to do it. ) Either you let XPath tool know that it should compare dates (it doesn't know from the start) with something like this:
my $query = '//collection/film[xs:date(./date) < xs:date("2012-01-01")]';
... or you just bite the bullet and just compare the 'yyyy' substrings:
my $query = '//collection/film[substring(date, 1, 4) < "2012"]';
The former is better semantically, I suppose, but requires an advanced XML parser tool which supports XPath 2.0. And the latter was successfully verified with XML::XPath.
UPDATE: I'd like to give my explanation of why your first query works. ) See, you don't compare dates there - you compare numbers, but only because of '=' operator. Quote from the doc:
When neither object to be compared is a node-set and the operator is =
or !=, then the objects are compared by converting them to a common
type as follows and then comparing them. If at least one object to be
compared is a boolean, then each object to be compared is converted to
a boolean as if by applying the boolean function. Otherwise, if at
least one object to be compared is a number, then each object to be
compared is converted to a number as if by applying the number
function.
See? Your '2012-09-24' was converted to number - and became 2012. Which, of course, is equal to 2012. )
This doesn't work with any other comparative operators, though: that's why you need to either use substring, or convert the date-string to number. I supposed the first approach would be more readable - and faster as well, perhaps. )
Use this XPath, to check the year
//collection/film[substring-before(date, '-') < '2012']
Your Perl script will be,
my $query = "//collection/film[substring-before(date, '-') < '2012']";
OR
my $query = "//collection/film[substring-before(date, '-') = '2012']";
Simply use:
//collection/film[translate(date, '-', '') < 20120101]
This removes the dashes from the date then compares it for being less than 2012-01-01 (with the dashes removed).
In the same way you can get all films with dates prior a given date (not only year):
//collection/film[translate(date, '-', '') < translate($theDate, '-', '']