[Q] Dates and SQLite - Android Software Development

Im using the java.sql.Date function to generate a Date from a DatePicker. Im having to take off 1900 from the Year after before the Date is generated for some odd reason, but never mind. I presume it's based on years AFTER 1900 and expecting a two digit date to be passed. I wonder how that'll work with the 1800's...
Anyhoo, I've seen the recommendations to use "Calendar" instead, but what I haven't quite figured out, is how you then get the date from the Calendar to format it in a variety of styles.
The simplest thing seems to be
Code:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
StringDate = sdf.format(date);
Or where I want to format a Date according to the System Locale:
Code:
java.text.DateFormat df = DateFormat.getDateFormat(context);
StringDate = df.getDateInstance().format(Date.valueOf(date));
Are these all the correct ways of formatting dates, or should I be using Calendar?
Thanks
Simon

Related

Trying to retrieve day and month

I'm running WM5 on a Treo 700wx and I'm trying to make my own little app, using Mortscript, to display the date on the carrier logo field. I've gotten as far as using:
Code:
GetTime dat, "m d, Y"
which will display in the format of
Code:
04 04, 2007
I would like to display the day name and the month name also, so it would look like this...
Code:
Wednesday, April 04, 2007
I figured out how to write the info into the carrier logo field, except I can't figure out how to retrieve and display the day name and month name.
So can I get some help please?
Thank you.
I figured it out. In the current release of Mortscript, the month can only be retrieved in numerical format. The day of week is the same. So I created a routine that will do the following:
if Week = 0 then WeekDay=Sunday
The month is also retrieved by a similar method:
if Month = 1 then MonthName=January
crazie.eddie said:
I'm running WM5 on a Treo 700wx and I'm trying to make my own little app, using Mortscript, to display the date on the carrier logo field. I've gotten as far as using:
Code:
GetTime dat, "m d, Y"
which will display in the format of
Code:
04 04, 2007
I would like to display the day name and the month name also, so it would look like this...
Code:
Wednesday, April 04, 2007
I figured out how to write the info into the carrier logo field, except I can't figure out how to retrieve and display the day name and month name.
So can I get some help please?
Thank you.
Click to expand...
Click to collapse
have you tried GetTime dat, "dddd, MMMM dd, YYYY"

Forcing date format strings

I got a problem with my calendar application, it uses a date format that's neither the long (17. October 2007) nor the short version (17.10.2007). Instead it uses a format with Roman numerals for month number, like 17. X 2007. The calendar app can't change this, it simply takes it from the OS, so is it possible to change it somehow, maybe in the registry?
Try using strftime (if you're using ANSI C) or GetDateFormat (Windows API). Changing the registry values will work, too, but that may change the way other apps present the date, which may not be what you want.

VB.Net + Multiple Databases

Hey Guys!
I need a little help in Sql Database programming in vb.net!
how can i Connect to 2 Databases and Join their queries?
Code:
Dim SQLcon As SqlCeConnection = Nothing
Dim strPDAPfad As String = AppDir & "\Catalogs\" & Config.QuestionFileName
Const strPDAPasswort As String = ""
SQLcon = New SqlCeConnection("Data Source=" & strPDAPfad & ";" & strPDAPasswort)
SQLcon.Open()
Dim SQLString As String = "SELECT * FROM QUESTIONS WHERE ID = '" & QuestionID & "'"
Dim SQLQuery As SqlCeCommand = New SqlCeCommand(SQLString, SQLcon)
i want to join 2 databases so i can order one table with the help of another!
Just Like I would have one Database with 2 Tables
"SELECT Questions.ID FROM Questions ORDER BY Stats.Wrong DESC"
I think this is not possible to to it directly. You might need to load the data of one into a temp table in the other db and then do the query.
Would be bad I need to do this very often
I will try to find out how to attach both files to an SQL Compact server and try that again
[edit] found nothing!
scilor said:
Hey Guys!
I need a little help in Sql Database programming in vb.net!
how can i Connect to 2 Databases and Join their queries?
Code:
Dim SQLcon As SqlCeConnection = Nothing
Dim strPDAPfad As String = AppDir & "\Catalogs\" & Config.QuestionFileName
Const strPDAPasswort As String = ""
SQLcon = New SqlCeConnection("Data Source=" & strPDAPfad & ";" & strPDAPasswort)
SQLcon.Open()
Dim SQLString As String = "SELECT * FROM QUESTIONS WHERE ID = '" & QuestionID & "'"
Dim SQLQuery As SqlCeCommand = New SqlCeCommand(SQLString, SQLcon)
i want to join 2 databases so i can order one table with the help of another!
Just Like I would have one Database with 2 Tables
"SELECT Questions.ID FROM Questions ORDER BY Stats.Wrong DESC"
Click to expand...
Click to collapse
Dim SQLString As String = "SELECT * FROM tbl1, tbl2 WHERE tbl1.ID = tbl2.ID and tbl1.QuestionID = '" & QuestionID & "'"
Thank you But I want to do this out of 2 Databases not out of 2 Tables!
I have not actually had the need to do so.
But I would check out LINQ, I have a feeling it should be able to do that.
I'll check it for you when I get home (at work at the moment).
LINQ how it works? I only find rare information for it!
how can I use it in VB.net 2008 ?
There is SQL Command named
UNION
which can Combined Identical Structure Database to Combine the Record from Both Table have you tried it
But how can I use that practically, i know in php is that easily because I know the alias of the Database but with my technic
New SqlCeCommand(SQLString, SQLcon)
there only can be one Database Per Connection
LINQ will read all the records from both databases into memory then do the merge join and give you the matched resultset. You could probably do it much better yourself. If you are going to repeat this join often, then for the sake of the user's patience, you should at least try to do it yourself.
If one table is known to be smaller (in KB) than the other, then I would cache that table in a Dictionary<keyColumn, DataRow> construct. Then I would open a data reader on the second table and process each of those rows by referring to the cached version of the first table.
Of course, I assume you have already ruled out the possibility of permanently merging the two databases? That would be the best solution. But perhaps there are two separate applications, to which you do not have the source code, responsible for maintaining these two databases, in which case I fully understand.
I need to Seperate both!
It is for my Driving Licence Trainer. and I want to Seperate Training Files from the Statistics
If one table is known to be smaller (in KB) than the other, then I would cache that table in a Dictionary<keyColumn, DataRow> construct. Then I would open a data reader on the second table and process each of those rows by referring to the cached version of the first table.
Click to expand...
Click to collapse
@ftruter Could you make an Example for using it for sorting?

[Q] Help - Locale Specific Date Formatting

Ok so I'm localizing my app.
It needs to display a date from a Gregorian Calendar in MM/dd/yyyy format for US. But in ES it would be dd/MM/yyyy
But not the current date, which is why I'm using gregorian so I can add days.
Code:
cal.add(Calendar.DAY_OF_MONTH, 49); // This is a gregorian calendar that I'm adding 49 days to.
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy", Locale.getDefault());
Textview01.setText(sdf.format(cal.getTime()));
Clearly this is formatting the text the way I want to for US. But since I'm setting a static format, it still displays MM/dd/yyyy for ES as well.
How can I get a Locale sensitive MM/dd/yyyy (US) or dd/MM/yyyy (ES) format without hard coding because I want to be able to do a bunch of languages.

[Q] Why is the Date Format not ISO 8601 compatible? Will you fix it?

just in case any of the actually coding people stopping by here,
i want to ask:
is it possible to implement a correct standard date format in PAC-ROM?
if one really cant figure it out, by 'correct standard' i mean:
http://en.wikipedia.org/wiki/Date_and_time_representation_by_country#ISO_8601 said:
International standard ISO 8601 (Representation of dates and times) defines unambiguous written all-numeric big-endian formats for dates, such as 1999-12-31 for 31 December 1999, and time, such as 23:59:58 for 23 hours, 59 minutes, and 58 seconds.
These standard notations have been adopted by many countries as a national standard, e.g., BS EN 28601 in the UK and similarly in other EU countries, ANSI INCITS 30-1997 (R2008), and FIPS PUB 4-2 in the United States (FIPS PUB 4-2 withdrawn in United States 2008-09-02).[1] They are, in particular, increasingly widely used in computer applications, since the most to least significant digit order provides a simple method to order and sort time readings.
Click to expand...
Click to collapse
some historical information:
http://en.wikipedia.org/wiki/ISO_8601#History said:
History
The first edition of the ISO 8601 standard was published in 1988. It unified and replaced a number of older ISO standards on various aspects of date and time notation: ISO 2014, ISO 2015, ISO 2711, ISO 3307, and ISO 4031.[2] It has been superseded by a second edition in 2000 and by the current third edition published on 3 December 2004. ISO 8601 was prepared by,[3] and is under the direct responsibility of, ISO Technical Committee TC 154.[4]
ISO 2014, though superseded, is the standard that originally introduced the all-numeric date notation in most-to-least-significant order [YYYY]-[MM]-[DD]. The ISO week numbering system was introduced in ISO 2015, and the identification of days by ordinal dates was originally defined in ISO 2711.
Click to expand...
Click to collapse
so since 1988 2015-01-18 is standard and not 2015/01/18 or 2015.01.18
it is quite strange that / and . are available and - is not ...
here are some details:
wiki said:
General principles
Date and time values are ordered from the largest to smallest unit of time: year, month (or week), day, hour, minute, second, and fraction of second. The lexicographical order of the representation thus corresponds to chronological order, except for date representations involving negative years. This allows dates to be naturally sorted by, for example, file systems.
Each date and time value has a fixed number of digits that must be padded with leading zeros.
Representations can be done in one of two formats – a basic format with a minimal number of separators or an extended format with separators added to enhance human readability. The standard notes that "The basic format should be avoided in plain text." The separator used between date values (year, month, week, and day) is the hyphen, while the colon is used as the separator between time values (hours, minutes, and seconds). For example, the 6th day of the 1st month of the year 2009 may be written as "2009-01-06" in the extended format or simply as "20090106" in the basic format without ambiguity.
For reduced precision, any number of values may be dropped from any of the date and time representations, but in the order from the least to the most significant. For example, "2004-05" is a valid ISO 8601 date, which indicates May (the fifth month) 2004. This format will never represent the 5th day of an unspecified month in 2004, nor will it represent a time-span extending from 2004 into 2005.
If necessary for a particular application, the standard supports the addition of a decimal fraction to the smallest time value in the representation.
Click to expand...
Click to collapse
and please dont make it depend on locale!
even if one choses english als gui-language the seperator should stay ISO8601 concurring!
well...
at least i can make some silly posts/topics in this forum...
hm...
any news
where do you see this?
i guess i missed the notification ...
i see it on 4.x on 5.x on 6.x on 7.x ! why is there a standard noone care's about... nothing changed

Categories

Resources