Format date from lookup table - datetime

My report has a data lookup table with dates in dd/mm/yyyy formart. When I bring it into Crystal it changes the data type to date-time instead of just date.
I tried converting to just a date within Crystal, but when I run a lookup based on parameters (10-1-2016 - 10-31-2016) I get a running cycle of dates. As soon as it hits 10-31-2016 it starts over from 10-1-2016.
I tried setting it to not provider duplicate values to no avail. How I could be doing this better?

If you just need to display the date without the time value, you can format the field when it displays in your report as "System Default Short Format" in the Format Editor. (Date and Time tab)
Otherwise leave the date as-is and create a seperate Formula Date({table.Field}) to use as "just the date". This way you keep the original datetime value as-is, but can use your new Formula when the time value needs to be removed.

Related

Formatted local time in a virtual generated column of SQLite

I want to store date in milliseconds, but also I want to see the formatted representation of it.
In order to not waste the drive space it makes sense to use a virtual generated column for this.
I wrote it:
DROP TABLE IF EXISTS example;
CREATE TABLE IF NOT EXISTS example (
time INTEGER,
formatted_time GENERATED ALWAYS AS (strftime('%Y.%m.%d %H:%m', time/1000, 'unixepoch')) VIRTUAL
);
INSERT INTO example (time) VALUES (1605960000000);
INSERT INTO example (time) VALUES (1615413202000);
It works, but I can't set the second modifier of strftime(format,timestring,modifier,modifier...) to get the local time. (It returns UTC time by default.)
When I use:
formatted_time GENERATED ALWAYS AS (strftime('%Y.%m.%d %H:%m', time/1000, 'unixepoch', 'localtime')) VIRTUAL
It throws Result: non-deterministic use of strftime() in a generated column when I insert a data.
While it works as expected:
select strftime('%Y.%m.%d %H:%m', 1615413202000/1000, 'unixepoch', 'localtime');
How to create a virtual column with formatted local time?
It's not possible.
Based on this answers:
Creating generate column based on today's date in SQLite
Computed column 'Month' in table cannot be persisted because the column is non-deterministic
SQLite requires to the value of a generated column would be the same on any machine in any time zone (be deterministic). Even for a virtual generated column.
In my case for time value 1615413202000 the formatted_time would be different for the same table opened in different time zones, so the the table would be "non-deterministic".
As a workaround it possible to create a view:
CREATE VIEW example_view AS
SELECT time, strftime('%Y.%m.%d %H:%m', time/1000, 'unixepoch', 'localtime') as formatted_time_local
FROM example;
(based on Shawn's answer)

Error with dates when filling a datatable

I am trying to fill a datatable in vb using SQLiteDataAdapter from a SQLITE database. There are 3 fields in the table that contain dates and they appear as either recent dates or "1899-12-30" . The Fill command generates a "String was not recognized as a valid DateTime." error. I cannot find a date entry that does not look valid, except "1899-12-30", is this a valid date?
Any other thoughts would be appreciated.
Brad
The short answer is 'yes'. I built a table with the three possible ways of storing dates, thus:
CREATE TABLE `JustDate` ( `Date_1` INTEGER, `Date_2` TEXT, `Date_3` REAL )
Then I populated each of those fields in one record with the value you suspect.
And then I did a trial query against the fields to see if sqlite would treat them as proper dates.

Oracle 11g SQL loader, time format issue

I am trying to load a .csv file using SQL loader. I get this error message on a column that should store time column:
column TIME.ORA-01843: not a valid month
In my .csv file time has the format HH:MM:SS but I can't understand why Oracle does not recognise it.
Using the command select * from nls_session_parameters; I see that the default time format is HH24.MI.SSXFF. I tried to change the time separator in my csv file but I got the same error result.
I have a very simple control file, that looks like below.
LOAD DATA
INFILE Cycling_Accidents0512.csv
INTO TABLE CYCLING_ACCIDENTS
FIELDS TERMINATED BY ','
(ID,
ACC_ID,
OSGB_EASTING,
OSGB_NORTHING,
WGS_LONG,
WGS_LAT,
POLICE_FORCE,
ACC_SEVERITY,
NUM_VEI,
NUM_CAS,
ACC_DATE,
DAY_WEEK,
TIME,
LOC_AUTH_DIS,
LOC_AUTH_HIGH,
FST_ROAD_CLASS,
FST_ROAD_NUMBER,
ROAD_TYPE,
SPEED_LIMIT,
JUNCT_DETAIL,
JUNCT_CONTROL,
SND_ROAD_CLASS,
SND_ROAD_NUM,
PED_HUM,
PED_PHY,
LIGHT_COND,
WEATH_COND,
ROAD_SUR_COND,
SPEC_COND,
CARR_HAZARDS,
URB_RUR,
POLICE_ATT,
LSOA_ACC_LOC,
VEI_TYPE)
If someone of you can help me to modify the control file in order to make the time format acceptable to Oracle, that would be appreciated. I tried to look up on other web resources but I haven't found anything that could help.
Thanks!
You mentioned querying the session NLS parameters, but the value you showed appears to be NLS_TIME_FORMAT, which is only used internally.
Oracle doesn't have a time-only type, so your field is presumably actually a DATE type (or possibly TIMESTAMP). The values in the column will have a date part, even if you ignore it.
SQL*Loader will use NLS_DATE_FORMAT to interpret the data file value for a DATE field. If that is DD/MM/YYYY then it would liberally interpret a value like 22:41:17 as the 22nd day of the 41st month - hence your error - in the year 17.
You can specify the date format model in the control file:
TIME DATE 'HH24:MI:SS',
The value in the table would have that time, on the first day of the current month.
The SQL*Loader documentation does refer to a TIME data type which I have never seen used, and I can't find any references to it anywhere, including MOS. A quick bit of experimentation hasn't helped. If I make the control file entry:
TIME TIME,
... then the record is rejected with ORA-00933: SQL command not properly ended. The log file also shows the data type as DATETIME HH24.MI.SSXFF, which looks related to the NLS_TIME_FORMAT value. I haven't found a way to make it accept that. If I change the column definition from DATE to TIMESTAMP then I get a different error, ORA-00904: "TO_TIME": invalid identifier, which is even stranger. It almost looks like these data types are defined in SQL*Loader for future use. (This discussion suggests they thought about adding TIME as a database type in 10g, but obviously can't verify that. And this is in the SQL*Loader reference at least back to 9i).

SQLite: select all rows made in a specific month

i want to get all entries from a SQLite table, which have the timestamp from the same month.
For example, the user can type in "July" and then i want to get all entries made in the 7. month.
The current "time"-column is a simple string and in the Format (DD.MM.YYYY HH:MM:SS)
Is there a way to do this with SQLite or will i need to use code in my program?
Assuming that your time strings have a fixed length, you could use a query like this:
SELECT * FROM MyTable WHERE time LIKE '__.07%';
However, you should always stored dates in one of the supported date/time formats so that you are able to use the built-int date/time functions.

Sql Server 2008 Removes 0's from Date

I am using asp.net/c# to build an application.I am accepting dates in British Format .
Suppose a user enters a date in the format 02/04/2001 , it gets stored in the table properly.However when i retrieve it the date is coming in this format 4/2/2001. I know that is coming in American Format , that's ok for me , my issue is that it is removing 0'sfrom numbers which are single digit. Will i have to check for such numbers and padding a zero before it and then display dates.Is there any way for this.
Thanks
You can format a date retrieved from SQL Server in .Net without worrying about the underlying value. Use culture-specific formatting if desired.
Standard Date and Time Format Strings
Custom Date Time Formats in .Net
Formatting Date and Time for a Specific Culture
Just to be clear (per Damien's comment) I am making the assumption that you are storing your values as Dates, DateTimes, DateTime2s, etc. in SQL not as strings. If that's not the case, conversion to a proper type should be the first step.

Resources