I'm trying to do a Datediff in VB.Net thats confusing me.
Basically I'm trying to do the following.
If DateDiff("D", Today(), rsData("Start")) > 0 Then
This is working fine when comparing the value from SQL with todays date. I however need to convert this to check the current month and if it matches then return whatever I'm trying to show below.
The SQL field format is as follows - 2012-01-03 00:00:00.0000000
Thanks!
'Is the data's month equal to today's month?
If Today.Month = CDate(rsData("Start")).Month Then
End If
Related
I'm new to the SQL world and im going crazy trying to figure out how to SELECT date from a datetime field in SQLITE.
Example: value <11/11/2005 14:56>, i just want to select <11/11/2005> for EVERY ROW.
I tried strftime(), date(), CAST() and other functions but the output its always NULL.
For example i tried querying SELECT strftime('%d/%m/%Y' , columnname) AS date FROM tablename;
OUTPUT: "NULL" in every row
Can someone help me understand what im doing wrong and how can i fix it? Thank you!!!
It always returns NULL because MM/DD/YYYY is not a valid sqlite date format. Treat the column as a string and use substr and instr to drop off the time portion. Something like (no guarantees, check the doc!)
SELECT substr(columname,0,instr(columnname,' '))
Re comment "how to order by the date in descending order"
This problem is a good argument (the best argument?) for storing the date in a sqlite date/time format. There is a strategy in this post for converting MM/DD/YYYY to YYYY-MM-DD (which sorts dates correctly).
If it's not too late, it would be advisable to change the date storage to a valid sqlite date format. strftime can be used to present the date as desired, and sorting will be accurate.
i use oracle forms 11g. And i pass To_Date(sysdate,'dd-mm-yyyy') that is inserted to the data base and data type of the column is date. but it is inserted as 22-10-0015 instead of 22-10-2015 can you help me?
i use procedure to insert data s and oracle from button click.i need to insert dd-mm-yyyy format to the data base how to do this?
sysdate is already a date, so it doesn't make sense to call to_date() for it. You are implicitly converting it to a string, and then explicitly back to a date. The implicit step is using your Forms session's NLS_DATE_FORMAT, which is presumably DD-MM-YY from the symptoms, so you're really doing:
to_date(to_char(sysdate,'dd-mm-yy'),'dd-mm-yyyy')
The implicit string version would show the year as 15 if you ran that on its own; and the explicit conversion correctly sees that as 0015 rather than assuming 2015.
You should just pass sysdate directly; but if you're trying to strip out the time so it shows as midnight, you can use the trunc() function:
trunc(sysdate)
SYSDATE is already a DATE. You don't need to use TO_DATE to convert it into a DATE.
What it's happening is that you're converting SYSDATE into a string and you're using the YYYY mask which will translate any year over 2000 into the 00's (that's why 2015 is being converted to the year 15). If you use the RRRR mask you will get the expected result:
TO_DATE(SYSDATE,'dd-mm-rrrr')
However, this is not a good idea as it's unnecesary and could fail if the NLS_DATE_FORMAT model used for the implicit conversion to string doesn't match.
I'm currently using Visual Web Developer 2010 (Express) and I'm trying to use the NOW() command within a SQL query to allow date selection but it doesn't work at random times and I'm lost to why it does this.
I'll give some examples, I'm from the UK my machine is set to standard time (sync with time.windows.com) and everything is fine but when I use the = NOW() it works but when it doesn't it seems the input date is mixed up, example below:
Currently my table is set as follows:
Table crew_example:
Column 1 : Date (In standard SQL time, so YYYY-MM-DD)
Column 2 : Initial
Column 3 : Surname
etc
My SQL query is as follows:
SELECT Date,
Initial,
Surname,
FROM crew_example
WHERE ( Date = { fn NOW() } )
ORDER BY Date
This function normal work and is currently working with another SQL query that users BETWEEN (DATE = { fn NOW() } + 1) AND { fn NOW() } + 6) (Which I had trouble when I set this up before but it magically fixed itself and never thought anything about it).
The date output when I hardcode doesn't work if I use today's date 27/11/2014 but works when I "americanise" it to 11/27/2014 even though the output comes in UK format 27/11/2014 00:00:00
Is there a way to unify the dates? I'm new to SQL queries so not use if I can use the NOW() command but change it to NOW() in format MM/DD/YYYY instead of what looks to be NOW() using my UK date type.
EDIT: Seems CURRENT_DATE may work....but any ideas if this is the best way?
Regards
Jamie
In T-SQL I would use something like this:
Where Date between cast(getdate() as date) and cast(dateadd(d,1,getdate()) as date)
I've never used a "pure" date column, so I'm not sure if you need to get rid of the time with the cast.
For dateadd() see: DATEADD (Transact-SQL)
For cast() see: CAST and CONVERT (Transact-SQL)
I am working on a SQLite Database which contains a column which stores value in format yyyy-MM-dd HH:mm:ss. Now I need to create a filter to select rows with filter as this datetime column.
Query:
Select * from tbl_locations where datetime >= '2013-09-11 00:00:00' and datetime <='2013-09-13 00:00:00'
Above query is returning null set despite containing values in this slot(which I verified using select statement without filter.)
Any suggestion how can i get the required data set?
Perhaps this excerpt from the SQLite documentation will help you:
1.2 Date and Time Datatype
SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values:
TEXT as ISO8601 strings ("YYYY-MM-DD HH:MM:SS.SSS").
REAL as Julian day numbers, the number of days since noon in Greenwich on November 24, 4714 B.C. according to the proleptic Gregorian calendar.
INTEGER as Unix Time, the number of seconds since 1970-01-01 00:00:00 UTC.
Applications can chose to store dates and times in any of these formats and freely convert between formats using the built-in date and time functions.
The date and time functions that you can use in your SQL to build your query are documented at http://www.sqlite.org/lang_datefunc.html
Ok, I tested this out in MySQL but hopefully it will work. I had a table that used timestamps, and changed the column to be of type text. Then I tried the following SQL query and got the same results that I normally would (besides trailing decimals)
SELECT timestamp(stock_quote_timestamp)
FROM stock.stock_quote
WHERE stock_quote_timestamp < timestamp('2013-10-07 11:05:30')##high_date
AND stock_quote_timestamp > timestamp('2013-10-03 14:09:03');##low_date;
So basically, just convert your text statements to timestamps so that they compare correctly. Oh, and you'll also need to state what else you're SELECTing, or you could do a compound select statement: SELECT *, timestamp(stock_quote_timestamp)...
I have an ASP.NET program that is writing date to an SQLExpress Database date field in DD/MM/YYYY.
When I look at the data in SQL Express it is stored as mm/dd/yyyy.
How can I configure it to store in DD/MM/YYYY format?
This is not possible, as the date is internally stored as a number, the DD/MM/YYYY or MM/DD/YYYY format is only the display format of the data. You can, however, change the way the data are converted to a string by SQL functions...
You are seeing the a rendered, localised version of an internal date representation (numbers of days since 01 Jan 1900 basically).
Don't worry about it. You'll get date back to your client (in an internal date representation) and this can be formatted how you like there.
Store the data normally. When you retrieve the data, do something like this on the code:
dateField.ToString("dd/MM/yyyy")
And your result will be: 11/04/2011
Maybe you can select that like this:
select CONVERT(varchar(12) , getdate(), 103 )