Is there a way in Groovy to get the duration between two Date objects? The duration format I'm looking for would be something like: 2 days, 10 hours, 30 minutes...
Thanks
Guys,
This is a quick one, i wanna parse a date that comes in this format "Sun May 23 22:00:00 UTC+0300 2010"
Is this a valid UTC DateTime? And how to parse it?
from google.appengine.ext import db
class Log(db.Model):
content = db.StringProperty(multiline=True)
class MyThread(threading.Thread):
def run(self,request):
#logs_query = Log.all().order('-date')
#logs = logs_query.fetch(3)
log=Log()
log.content=request.POST.get('content',None)
log.put()
def Log(request):
thr = MyThread()
thr.start(request)
return HttpResponse('')
error is :
Exception in thread Thread-1:
Traceback (most recent call last):
File "D:\Python25\lib\threading.py", line 486, in __bootstrap_inner
self.run()
File "D:\zjm_code\helloworld\views.py", line 33, in run
log.content=request.POST.get('content',None)
NameError: global name 'request' is not defined
I have a database that worked fine until I decided to add a log onto the page. here is what I have now:
<body>
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST')
{
require("serverInfo.php");
mysql_query("UPDATE `cardLists` SET `AmountLeft` = `AmountLeft` + ".mysql_real_escape_string($_POST['Add'])." WHERE `cardID` = '".mysql_real_escape_string($_POST['Cards'])."'");
echo "\"" .$_POST['Add'] ."\" has been added to the inventory amount for the card \"". $_POST['Cards']. "\"";
mysql_query("INSERT INTO `log` (`changes`, `amount`, `cardID`, `person`, Date)VALUES('ADDED','$_POST['Add']','$_POST['Cards']', '$_POST['Person']', NOW())");
mysql_close($link);
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<?php require("serverInfo.php"); ?>
<?php
$res = mysql_query("SELECT * FROM cardLists order by cardID") or die(mysql_error());
echo "<select name = 'Cards'>";
while($row=mysql_fetch_assoc($res)) {
echo "<option value=\"$row[cardID]\">$row[cardID]</option>";
}
echo "</select>";
?>
Amount to Add: <input type="text" name="Add" maxlength="8" />
Changes Made By: <select name="Person">
<option value="justin">Justin</option>
<option value="chris">Chris</option>
<option value="matt">Matt</option>
<option value="dan">Dan</option>
<option value="tim">Tim</option>
<option value="amanda">Amanda</option>
</select>
<input type="submit" name ="submit" onClick= "return confirm(
'Are you sure you want to add this amount?');">
</form>
<br />
<input type="button" name="main" value="Return To Main" onclick="window.location.href='index.php';" />
</body>
</html>
it works fine until I added the:
mysql_query("INSERT INTO `log` (`changes`, `amount`, `cardID`, `person`, Date)VALUES('ADDED','$_POST['Add']','$_POST['Cards']', '$_POST['Person']', NOW())");
mysql_close($link);
Can anyone see what is going on?
In my understanding a singleton object will destroy only when the application is about to terminate. So in C++ I write a Singleton class to log my application and in that Singleton logger's destructor I log the time when my application was terminated. Things worked perfectly in C++.
Now I want to have that same logger in Java, as in java there is no destructor so I implemented the finalize method for that singleton logger. But it seem that finalize method actually never get called.
So, I add that System.runFinalizersOnExit(true); line, somewhere in my code (though I know it is deprecated) and that finalize method get called every time before termination of the app. But still there is a problem! If I try to write anything on file in that finalize method, It does not work, though System.out work without any problem! :(
Can you guys help me on this problem? Here is a sample code of what I am try to do:
Singleton Logger Class:
public class MyLogger {
FileWriter writer;
private MyLogger() {
try {
this.writer = new FileWriter("log.txt");
}
catch (IOException ex) {
}
}
public static MyLogger getInstance() {
return MyLoggerHolder.INSTANCE;
}
private static class MyLoggerHolder {
private static final MyLogger INSTANCE = new MyLogger();
}
@Override
protected void finalize () {
try {
super.finalize();
System.out.println("Here"); //worked correctly.
this.writer.write(new Date().toString()+System.getProperty("line.separator"));
this.writer.write("End");
this.writer.flush(); //does not work!
this.writer.close();
}
catch (Throwable ex) {
}
}
public synchronized void log(String str) {
try {
this.writer.write(new Date().toString()+System.getProperty("line.separator"));
this.writer.write(str+"\n");
this.writer.flush();
}
catch (IOException ex) {
}
}
}
Main:
public class Main {
public static void main(String[] args) {
System.runFinalizersOnExit(true);
MyLogger logger = MyLogger.getInstance();
logger.log("test");
}
}
I've got a bash script that reads input from a file like this:
while IFS="|" read -r a b
do
echo "$a something $b somethingelse"
done < "$FILE"
The file it reads looketh like this:
http://someurl1.com|label1
http://someurl2.com|label2
However, I'd like to be able to insert the names of variables into that file when it suits me, and have the script process them when it sees them, so the file might look like this:
http://someurl1.com?$VAR|label1
http://someurl2.com|label2
So $VAR could be, for example, today's date, producing an output like this:
http://someurl1.com something label1 somethingelse
http://someurl2.com?20100320 something label2 somethingelse
im doing some practice sql problems
one of the questions is:
Prepare a shipping statement for
customer 'C001' it should show the
date, the legend 'Delivery' and the
total value of the products shipped on
each day.
'delivery' is not a table nor is it a column in any table.
what does legend mean??
it puts item1 down as DESC for some reason.
edit:
$sql_result = mysql_query("SELECT post, name, trip, Thread, sticky FROM (SELECT MIN(ID) AS min_id, MAX(ID) AS max_id, MAX(Date) AS max_date FROM test_posts GROUP BY Thread ) t_min_max INNER JOIN test_posts ON test_posts.ID = t_min_max.min_id WHERE Board=".$board." ORDER BY sticky ASC, max_date DESC", $db);
http://prime.programming-designs.com/test_forum/viewboard.php?board=0&page=3
For example:
void Date::month(unsigned int inMonth) {
assert(inMonth <= 12);
_month = inMonth;
}
If this is not good practice, what is the correct way to go about this?
I need to track the date and time a user was created in my mysql database. I have column called 'created' and the data type as TIMESTAMP.
The problem is that when a user changes their password or other information the TIMESTAMP value changes. How can I set this to not change????
I am able to read the phone no, subject, sender, and date and time and i need some help on reading the body of the email, i know that it can be read using openproperty but not able to move far.. hope help from u people thanks in advance.
Hi,
Not able to execute a query ,i need to check if end date is greater than today in the following query
Getting an error invalid query
select * from table1 where user in ('a') and END_DATE >'2010-05-22'
getting an error liter string does not match
I want to remove a cookie I set. If I do this by giving it a expiration date sometime in the past it gets marked as "expires: at end of session". I've noticed that other sites manage to delete the cookie immediately somehow. For example when you logout here on stackoverflow the "user" cookie disappears right away. How?
I recently played with MongoDB in Rails using Mongoid. I like the ability to define attributes for models within the model file (as opposed to in migrations):
class Person
include Mongoid::Document
field :name, :type => String
field :birthday, :type => Date
end
For projects that cannot use a schema-less database, does a similar feature exist? Any gems or plugins that generate schemas from a similar syntax would be greatly appreciated.
Thanks.
Hello,
In my table I have a field named eventdate in datetime format like 2010-05-11 00:00:00.
How do i make a query so that it adds one day to the eventdate eg if today is 2010-05-11, i want to show in where clause to return all records with tomorrow's date.
I'd like to script p4 a little. Unfortunately, some of the filenames that we're tracking have "@" in the filename.
The filenames are in the form [email protected]. If I try to do something like p4 sync a\@b.xml on a mac (or p4 sync [email protected] on windows) it gives the error:
Invalid changelist/client/label/date '@b.xml'
Is there another way to escape it that perforce will recognize?
I am working with DateTime, trying to get date in the format like this:
03.05.2010-04.05.23 that is: dd.MM.yyyy-HH.mm.ss
I'm using DateTime.ParseExact to try to achieve this (maybe wrong)
So far I have:
var dateInFormat = DateTime.ParseExact(DateTime.Now.ToShortDateString(), "dd.MM.yyyy.HH.mm.ss", null);
But can't quite get exactly what I want. Basically I want to keep the 0, for example time is 05:03:20 PM I don't want it to show like 5:3:20 PM
Any ideas?
Hi
I would like to zip a bunch of files (.exe and .dll) before I overwrite them with the new build. Is there a simple way to zip files without using some sort of dll?
Just creating a folder with the build number / date time stamp will also work great. How do I pass parameters from the cruise control build process into my Powershell script that will do the work then?
Is this a sustainable way to do things?
Thanks
Hi, i have an application deployed in Air, written in AS3 that client wants to install and test, i have developed a simple license app, but he is pushing for a full license witch he said he will fully paid on next monday.
How would you create a procedure in AS3 to deactivate application next monday? How secure will it be? will simply changing machine date will bypass this?
I did following:
create or replace type my_row as object
(
lname varchar2(30),
fname varchar2(30),
MI char(1),
hohSSN char (9),
hohname VARCHAR2(63),
hohDob char(10),
dob DATE
);
create or replace type eiv.my_rec as table of eiv.my_row;
but then doing query like:
my_records my_rec
select '', '', '', '', '', '', sysdate bulk collect into my_records from dual;
gives error ORA-00947: not enough values
what can i be doing wrong here?
string queryString = "SELECT SUM(skupaj_kalorij)as Skupaj_Kalorij "
+ "FROM (obroki_save LEFT JOIN users ON obroki_save.ID_uporabnika=users.ID)"
+ "WHERE users.ID= " + a.ToString() + " AND obroki_save.datum =?";
using (OleDbCommand cmd = new OleDbCommand(queryString,database))
{
cmd.Parameters.Add("@datum", OleDbType.Char).Value = DateTime.Now.ToShortDateString();
}
Why doesn't the parametr datum get the date value? (the value of at least one complex parameter has not been determined )
I have tried below but not getting any result back
Not sure if i'm doing this well.
Can i filter in the foreach or in my if statement
Thanks in advance
[DateTime] $CreatedDate = $item["Created"]
$convertedCreatedDate = $CreatedDate.ToString("yyyy-MM-dd")
$today = (Get-Date).AddDays(-1).ToString("yyyy-MM-dd")
foreach ($item in $list.items | where {$convertedCreatedDate -eq $today}) {
if ($list.items | where {$convertedCreatedDate -eq $today})
{
Write-Host $item["Created"]
}
Write-Host $item["Created"]
}
hi everyone
this is a cakePHP question about datetime database insertion mismatch, i jumped in to this project while the whole thing is already built around 70%.
here's what happen, every time i insert a data that contain a datetime, the inserted time doesn't match the inputted date, and the mismatch has no pattern or what ever, in some table the differences is 5 hours, while in others it could be 12 hours, 7 hours, or even 15 hours.
i have traced this by investigating the controller, the model, the app_controller, everything but i don't find anything that indicate a datetime insertion rules.
if the view :
echo $form->input('start_date', array('label' => __l('start date'));
i can't even find in the controller anything like:
$this->data['current_controller']['start_date'] = $this->data['current_controller']['start_date'];
when i use pr($this-data); to print the posted data, this is shown:
[start_date] => Array
(
[month] => 02
[day] => 16
[year] => 2011
[hour] =>
[min] =>
[meridian] =>
)
so i figured doing something like:
$yearMonDay = $this->data['current_controller']['start_date']['year']."-";
$yearMonDay .= $this->data['current_controller']['start_date']['month']."-";
$yearMonDay .= $this->data['current_controller']['start_date']['day'];
if(!empty($this->data['current_controller']['start_date']['hour'])){
$hourMinSec = $this->data['current_controller']['start_date']['hour'].":";
$hourMinSec .= $this->data['current_controller']['start_date']['min'].":";
$hourMinSec .= $this->data['current_controller']['start_date']['meridian'];
}else{
$hourMinSec = "00:00:00";
}
$this->data['Deal']['start_date'] = $yearMonDay." ".$hourMinSec;
just to make sure
the funny thing is that those posted datetime is inserted into the database with the mismatch value anyway. it's getting pretty frustrating, is there any suggestion on where else should i find the codes that define how the datetime should be inserted? or probably give me a clue on how to override those mismatched insertion rules?
thanks
I am working on my first Drupal project on XAMPP in my MacBook. It's a prototype and receives positive feedback from my client.
I am going to deploy the project on a Linux VPS two weeks later. Is there a better way than 're-do'ing everything on the server from scratch?
install Drupal
download modules (CCK, Views, Date, Calendar)
create the Contents
...
Thanks