I am using a RadTimePicker which I want to be able to pass the time only to the database as it passes a date even when you don't set one.
How I want to pass it to the database:
10:30
How I want it to be stored in the database:
10:30
Error I received in Visual Studio:
"Cannot convert String to TimeSpan"
This was because of the RadTimePicker I am using automatically passes a date even if there isn't one set, so it passes 01/01/0001 00:00:00 and I don't need or want the date part.
Because I couldn't get it working I decided to do a workaround using varchar but then I was shown how to properly set it up using time datatype.
I used this for the conversion to fix my error I got the 1st time
Cast String to TimeSpan
The solution for that is shown below.
I have now corrected my answer to replicate the 'correct' way of storing time.
Input Fields:
How it's stored in the database:
Data Types in the 'Update DB stored procedure' and the database table:
Declaring global Date Variables
How to Pass only the time:
Passing Data using Dictionary
Hope this helps!
Related
I am trying to declare a session variable to a date value but the variable keeps reading in as string or numeric.
I've tried setting the date with varying formats, with and without time, in utc format, etc but nothing has worked. All are seen as text unless i don't use quotes or apostrophe's, in which case 2019-09-01 results in 2009 number type.
set(myDate)='2019-09-01'
set(myDate)="2019-09-01"
set(myDate as date)='2019-09-01'
set(myDate)='2019-09-01 18:25:53.820000000Z'
no matter what i try when i run show variables it doesn't show as date or timestamp data type. if i run set(myDate)=current_timestamp() that works fine but I do not want the current date.
Finally figured it out so maybe this will help someone else. When setting the variable, use to_date to cast the value at the same time. e.g:
set(myDate)=to_date('2019-09-01');
Hi Crystal Developers,
I am trying to write a Crystal Report (v2011) that accepts user input for start date and end date. I have set up 2 parameters to do this.
The report connects to the database via a Command object, and I want to reference the parameters in the command object so that data retrieval is quick.
All date data in the database is stored in UTC.
When the user is prompted to enter dates, they are going to input in local time (they are not going to know about UTC...nor should they).
I cannot see a way to convert the user date data into UTC and use it in the command object. Crystal has ShiftDateTime, but this can only be used in formulas, and I don't really want to hard-code a value in the SQL of the command object either.
Any ideas?
Thanks
Instead of adding the database table within ShiftDateTime you add the user inputted parameter
My user input data from records is "formula": {?DateFrom} to {?DateTo}
as opposed to "is Between" {?DateTimeSearch}
Using ShiftDateTime:
DATA.DATE_DATA_UTC = (ShiftDateTime((({?DateFrom}),"","UTC,0")) to (ShiftDateTime((({?DateTo}),"","UTC,0"))
I'm moving data that is currently been stored as a int to DateTimeOffset.
Example here is the starting value 1341190841 and when I use this query :
dateadd (s,Call.StartTime, '1970-01-01') AS StartTimeDate
It returns this value 2012-07-02 01:00:41.000 which is correct. However I'm using SSIS to move data from one db to another and when the data is in the new table the StartTimeDate now looks like this 2012-07-02 01:00:41.0000000 +01:00.
Anyone got any idea how to remove the +01:00? I want to keep the time as it is in the first query.
I wasn't able to reproduce that behaviour (even with two SQL Servers in different timezones), so this may not be exactly what you want, but you can "fix" the TZ offset (the "+01:00") after copying the data by updating the StartTimeDate column with the function ToDateTimeOffset like this:
UPDATE the_table SET StartTimeDate = TODATETIMEOFFSET(StartTimeDate, 0)
That will leave the date and time untouched while adjusting the offset to the specified one (0 since you want it to "adjust" the TZ from +1 to 0).
I'm trying get an Excel Range and copy into an array of objects with Vb.Net.
This is not a problem. I use the following code:
Dim vValues(,) As Object = ExcelApp.Range(vRange).Value
And works fine; but I have a the following case:
In the column "C"; the value has a specific format and internally has another value.
My question is:
Somebody know the way to get the information exact as the user see?
I'm trying to get the information without use a For ... Each or some kind of cycle.
I'm also tried to avoid use "text to columns" function.
Both seems right solutions, but would impact the performance with a lot of data.
FYI: Also I can get the information through the ODBC connection; but I'm searching the solution using a Range
Exactly what the user sees is the Text property. But you cannot have an array of that, you will have to query each cell individually.
You are getting a Double value in your array instead of a DateTime value because you have "Time" formatting applied in Excel. If you had a format from the "Date" category, Excel would instead send a proper Variant/Date, not a Double that represents it.
Another option would be constructing the DateTime objects on the .NET side, provided you know in which columns they should be.
We have recently moved some data from an SQL Database instance to another one in another location.
I seemed to have noticed that there are some facets of our old database instance where the date is passed as String to the SQL server and SQL server is able to parse it properly. For example, the application would simply pass a string value of "15/01/2010" and the database would immediately recognize it as 5th of January 2010. Is there a setting in SQL server which I need to turn on or modify cause right now, when I passed the same string value, what happens is that an error is being generated cause it cannot understand the string value passed as a date.
Thanks for your inputs.
try
SET DATEFORMAT dmy
but you should only use 'safe' formats when using strings
same formats are YYYYMMDD and yyyy-mm-ddThh:mi:ss.mmm (no spaces). It doesn't matter with these 2 formats what your language settings are
Take a look here: Setting a standard DateFormat for SQL Server
If you need to convert output use cast or convert
select convert(varchar(30),getdate(),101)
03/08/2010
select convert(varchar(30),getdate(),101) +' '
+ convert(varchar(30),getdate(),108)
03/08/2010 15:21:32