I have a sybase database and would like to create a new bigdatetimefield by adding time to a current bigdatetimefield
for example
I have a date1 field = 8/31/2015 2:23:49.529000 PM
I have a date2 field = 8/31/2015 7:23:49.529000 AM
I have a mainDate field = 8/31/2015 2:24:46.112000 PM
I would like to make a new field that is the mainDate field minus the difference in time between the date1 field and the date2 field
So in this case the new filed would be 8/31/2015 2:24:46.112000 PM - (8/31/2015 2:23:49.529000 PM - 8/31/2015 7:23:49.529000 AM)
Any idea how to do that in sybase?
SELECT new_dt = DATEADD(ss, datediff(ss,date1,date2),mainDate)
FROM my_table
That's only accurate to seconds though. You can use millisecond or microsecond.
Related
So I am building a project where I need to fetch date from the database and on the basis of the given month,
as I need to find customers who have birthday on the given month. I have a query that works perfectly fine in the SQL server but I don't get its equivalent in Linq.
So here is my query that runs in SQL
SELECT * FROM CustReg
WHERE DOB LIKE '_____month%'
I need to match that month as it should come in the 6th position of that DOB string.
Demo Database-
Id Name DOB
1 AB 1995-02-20
2 CD 1998-04-13
4 EF 1991-02-15
5 GH 1988-06-8
6 IJ 2000-02-09
Query - Select all Employee whose birthday comes on feb.
Expected Output - AB,EF,IJ.
PS- I have taken datatype of DOB string not Date or DateTime.
I also have month in string (for eg '02' for feb)that I have fetched from the input date.
If I have understood your question right, may be the following code helps.
First create a enum of Months,
public enum Month
{
Jan=1,Feb,Mar,Apr,May,Jun,July,Aug,Sep,Oct,Nov,Dec
}
Now use the following query to get what u wanted,
Month requiredMonth = Month.Feb;
var res = CustReg.Where(x => (Month)Enum.Parse(typeof(Month), x.DOB.Substring(5, 2)) == requiredMonth).Select(x => x.Name);
foreach (var item in res)
{
Console.WriteLine(item);
}
Strange results on a saved date in GAE (Python with ndb library).
The inbound string from a web form is %a %m/%d/%y formatted (Fri 3/3/17).
That's parsed with datetime.strptime to get a date value.
When it's saved in a DateProperty() field, the value is consistently the day before, at 16:00:00.000 PST.
postDate = datetime.datetime.strptime(self.request.get('date-'+
hashed_id),'%a %m/%d/%y')
logging.info('postDate as Date: %s',postDate)
postDateStr = datetime.datetime.strftime(postDate,'%D')
logging.info('postDateStr: %s',postDateStr)
thisPost = ScheduledPost(id = postID,
...
postDate = postDate,
postDateStr = postDateStr
)
log results:
postDate as Date: 2017-03-03 00:00:00
postDateStr: 03/03/17
so far so good, right? but in the Datastore interface, that record shows:
PostDate: 2017-03-02 (16:00:00:000 PST)
PostDateStr: 03/03/17
Oops.
Workstation is in Pacific time - but leaving that aside - date queries seem to confirm that the date is wrong. Assuming today is 3/3/17 -
today = dt.datetime.now()
ScheduledPost.query(ScheduledPost.postDate == today).fetch()
No record returned.
Saving date as string, and querying on date as string, are feasible workarounds for this project. Just thought it merited posting - anyone seen this? Advice?
The datetime you're generating on appengine is UTC, and it gets stored as that datetime, without timezone information.
When you're viewing it, it's being converted to pacific-time.
The query you're doing is incorrect: you're generating a datetime, not a date, so the time you're comparing with is going to be different.
My calendar script is loading fine but the table not reflecting any changes.
Below the code i am using:
Calendar:
load Distinct
"sDate",
Year("sShipment Date") As PostingYear,
Month("sShipment Date") As PostingMonth,
Week("sShipment Date") As PostingWeekOnly,
WeekDay("sShipment Date") As PostingWeekDay,
Day("sShipment Date") As PostingDay,
'Q' & Ceil(Month("sShipment Date")/3) As PostingQuarter
resident myTable;
Temp:
Load
min("sDate") as minDate,
max("sDate") as maxDate
Resident Calendar;
Let varMinDate = Num(Peek('minDate', 0, 'Temp'));
Let varMaxDate = Num(Peek('maxDate', 0, 'Temp'));
I create calendar object but when I pick the date I don't see change in my straight table.
I want when change start and end date to get result in my table between start and end date. Does anyone have an idea?
In your calendar properties use the field selection and use an expression.
=MonthName(sdate)
For example and then this will give you the full range to select from.
This will then reflect in your straight table.
I am trying to query a SQL Server database to check for the MAX date in one field and to select the next day for input into another process. I am able to query the database and pull back a date, but I can't convert it into a date object.
Here is what I tried:
tmpMaxDate <- sqlQuery(dbhandle, 'select MAX([date]) + 1 from dbo.My_Data ')
tmpMaxDate
1 2016-01-02
IsDate(tmpMaxDate)
[1] FALSE
maxDate <- as.Date(tmpMaxDate)
Error in as.Date.default(tmpMaxDate) :
do not know how to convert 'tmpMaxDate' to class “Date”
maxDate
NULL
IsDate(maxDate)
[1] FALSE
maxDate <- as.Date(tmpMaxDate, format = "%Y-%M-%D")
Error in as.Date.default(tmpMaxDate, format = "%Y-%M-%D") :
do not know how to convert 'tmpMaxDate' to class “Date”
IsDate(maxDate)
[1] FALSE
maxDate
NULL
The packages I am using are RODBC, chron, lubridate, and RSQLserver
I thought I needed to convert to a date object to use the date from SQL Server in R.
Any thoughts on why my date won't convert? Do I need to convert to be able to use that date to filter data in R?
DateVar <- sqlQuery(dbhandle,"SELECT CONVERT(varchar(10),GETDATE() + 1,101) as Date")
DateVar
NewDate <- as.Date(DateVar$Date, format = "%m/%d/%y")
NewDate
I think the trick for me to was give the date response a column name and then reference the column (being the specific string value needed to convert) name in the conversion.
class(NewDate)
will show as "Date"
I have written a batch job. In this batch job i have a condition to take date > = 1/1/2012
I am not able to give the date in the query. can you please help me.
global Database.QueryLocator start(Database.BatchableContext BC) {
system.debug('Inside start');
//date mydate = date.valueof(1/1/2012);
return Database.getQueryLocator('select name from opportunity');
}
I have given it in 2 ways
1st is :
took the date into a date field and give the condition as date >= :mydate
(shows an error in debug log as Invalid date: 0 )
and
2nd way when i gave the date their itself as date >=: 1/1/2012
(it shows as error in debug log as unexpected token: / )
can you please help me
Thanks
Anu
You must follow the proper date format
YYYY-MM-DD
select name from opportunity where mydate >= 2012-01-01
More information here