Delphi does not use *nix timestamps. In other apps I have converted to *nix before storing in MySql and reversing that when retrieving.
Now I would like to try using DB aware components for the first time. How will it work for tiemstamps? Should I (can I) store in Delphi tiemstamp format? Or shoudl I convert to *nix before storing?
For normal use your do not need to do anything.
I had used Delphi / MySQL for many year and all data access components I had used (dbexpress / zeros / MyDAC) do the conversion automatically. In case I need to manually specify the timestamp value, I just provide the text format ("yyyy/mm/dd hh:nn:ss")
Related
How do I convert data that is in text to date in MySQL?
The data I have is like this
20210422
20210423
I want the data in this format
2021-04-22
This depends on what kind of database you are using, and a quick google search should turn up the proper conversion function for your DBMS. For example, MS SQL date conversion is done via CAST and CONVERT functions: CAST and CONVERT
I guess here there is some misunderstanding between date-storage and date-representation, but could you please try(for MS SQL Server)
DECLARE #InDate1 DATE='20210422';
SELECT #InDate1 AS ORIGG,CONVERT(DATE,#InDate1,120)AS CONV;
Setup :
Angular 8 + Spring boot 2.2.3 + (Oracle 12.1 / PostgreSQL 12.3)
We are building a approval System where User can fill online form like google forms and can submit for approval. Rather than normalizing form structure , we'll be storing metadata in JSON format in our DB.
Values that are filled in form would also be going as JSON format in DB.
One point come up as a concern , in DB we can store date in particular format like 12-May-2020 which would be consistent across all inserted data as this data might be used to construct reports in near future.
Based on pros/cons of this approach need to decide on DB / data model as well.
So,
Is there any way I can enforce date format in JSON
If this cannot be done in JSON , what options do i have at Angular 8 / Spring boot application level which would enforce all developers / date components / date fields to use same date format.
If these cannot be done , how can I handle different formats in Query over JSON data that would be used in reporting or otherwise , both in Oracle and PostgreSQL
Regards
The proper solution to your problem is to create a real, normalized date column.
If for some reason you can't or don't want to do that, I would create a check constraint that validates the date format by trying to cast it to a real date value.
The following is for Postgres, but you can create something similar for Oracle as well:
create table the_table
(
form_data jsonb,
constraint check_valid_date check ( (form_data ->> 'entry_date')::date is not null)
);
Obviously you will need to adjust the expression that gets the date value from the JSON to match the key and path inside your json value.
The cast to date will require that the date value is entered using the ISO standard format, yyyy-mm-dd which is the only "consistent" way to store a date as a string.
Alternatively you can use to_date() with a format mask:
check ( to_date(form_data ->> 'entry_date', 'yyyy-mm-dd) is not null)
in DB we can store date in particular format like 12-May-2020
You are mistaken, Oracle doesn't store date in that format. It is internally stored in TYPE12/13 data type. Each bit represents different parts of the date. What you see is a human readable format displayed according to your locale-specific NLS settings or using TO_CHAR with format mask.
To keep it aligned across all platforms, use the globally accepted ANSI standard date literal which uses a fixed format 'YYYY-MM-DD'.
For example:
DATE '2020-05-21'
I need to converts costs into Vietnam and Indonesia.
Is there any way that we could format the value dynamically using the culture of the country currency?
Example:
7859948,84 to 7,859,948.84
Thanks in advance
Format your data at the presentation layer, not in the database. Store it as the appropriate data type in the database (probably money), then format it using the correct culture in whatever application you're using to present to the user, using the user's preferred culture settings.
if you must do it in the database:
For SQL Server 2008R2 and earlier, you'll have to use a CLR function. See this SO answer
It can be done in T-SQL as of SQL Server 2012 using FORMAT() and the vi-VN culture string.
select 7859948.84, format(7859948.84,'N','vi-VN');
Yields 7.859.948,84 which, according to MS's culture settings, is the correct format for Vietnamese numbers.
But even though you can do it in newer versions of SQL Server, it should still be done in the presentation layer.
I have a game created in ActionScript 3 which uses a MySql database / PHP to store and reload the game state between player logins. I have strings(varchars), ints, big ints etc being saved. On my local WAMP server this seems to work perfectly. On upload however, my host database will not store the strings. It will store strings used for the login / registration (username, email etc) but not the strings created for some of the game data ( a game character's color, gender, hair style, shoes etc are stored as one long string).
I have a php file which deals with login and registration and a second dealing with all game store / load, plus a number of AS3 interface classes which talk to this php file. But the same AS3 class / php file will successfully store ints etc whilst failing to store string data.
I checked the column names and that the local and host databases are identical, and have set the collation to utf8_bin for all the string fields in case there was some sort of collation issue. I am new on databases...
In the php I am using something like:
$id=$_POST['userId'];
$value1=$_POST['array1'];
$value2=$_POST['array2'];
$what=$_POST['action'];
if ($what === 'storeStuff'){
mysqli_query($db,"UPDATE mytableName SET field1=$value1, field2=$value2 WHERE userid='$id'") or exit("systemResult=fail");
exit("systemResult=success");
}
Here is an example of the type of string info being saved successfully in my local database table, but which gives me a 'systemResult = fail' on my hosted database:
0,1,0|0,0,3|0,1,0|0,1,1
Any ideas what is going on?
Thank you.
I resolved my problem after 'phoning a friend' who suggested I look at the 'magic quotes' issue, and add some code to check if they were turned on in the host server and if so, turn off. He was right. Turns out it was the quotes surrounding the strings which were causing a problem, as different server configurations / versions will cause differing results. To ensure a consistent result independent of server configuration / version I used the solution offered in the php.net manual.
Here is the link I used which includes the needed code to identify their status and disable them.
http://php.net/manual/en/security.magicquotes.disabling.php
A silly question maybe but I wanted clarification. I've created a script that has a date parameter like so:
DECLARE #dateparam as datetime
SET #dateparam = '01-01-2013 00:00:00'
This looks like it is working when I test it even if the date string is not in "correct" format yyyy-MM-dd hh:mm:ss. I changed my computer regional settings to English and the script still did what it was supposed to do.
Is this because of SQL Server 2008 R2 that I have in my computer that it knows how to convert the date or can I ran into trouble with using a dateformat like I have used?
Converting 01-01-2013 won't expose issues such as which 01 is the month, and which is the day.
It's not a safe format.
The safe formats (for converting to datetime, rather than to datetime2) are:
YYYYMMDD 20121201
YYYY-MM-DD'T'hh:mm:ss 2012-12-01T10:43:29
YYYY-MM-DD'T'hh:mm:ss.mil 2012-12-01T10:43:29.337
Stick to those and only those. (The examples all represent the 1st December 2012)
Or, better yet, don't treat dates as strings at all, if you can avoid it. If you're, for example, calling SQL Server from .NET code, keep that dates as DateTimes in your code, and let ADO.NET and SQL Server deal with any required translations to make them become datetimes - without translating them to and from strings.
You're making an implicit conversion from something that looks like a date, but inf fact is a string ( '01-01-2013 00:00:00'). Rather than trusting on SQL Server to make the correct guess in what format the string is in, you should make the conversion explicit by specifying the format.
This can be done by using CONVERT (not CAST) and specify a 'style'. The different styles are listed here: http://msdn.microsoft.com/en-us/library/ms187928.aspx.