If i set the property "format" of a TDateTimePicker component (Delphi XE10) eg. ddd d/m/yyyy then it shows Tue 14/47/2016 !! and the date 31/12/2016 as 31/0/2016 !
what is happening, please ?
That date format is incorrect. You need to use uppercase M, as is shown in the TDateTimePicker.Format documentation. Lower-case m represents minutes in a time format.
m The one- or two-digit minute.
mm The two-digit minute. Single-digit values are preceded by a zero.
M The one- or two-digit month number.
MM The two-digit month number. Single-digit values are preceded by a zero.
MMM The three-character month abbreviation.
MMMM The full month name.
ddd MM/dd/yyyy shows Tue 06/14/2016, and ddd dd/MM/yyyy shows Tue 14/06/2016.
Related
I would like to convert Julian Date value to normal date. Can anyone please help me?
I have tried JulianDateToDateTime(somedouble value) but it raised exception.
Then I tried ModifiedJulianDateToDateTime(some double value) it posted a date but its totaly wrong.
For example my Julian Value is 226. It says that it must show 14 th August. But I couldnt convert it usig delphi.
Thanks
System.DateUtils.JulianDateToDateTime converts a Julian Date to a TDateTime value.
From documentation:
The Julian date is the number of days, including fractional days, since 4713 BC January 1, Greenwich noon.
And for System.DateUtils.ModifiedJulianDateToDateTime:
The modified Julian date is the number of days, including fractional days, since Greenwich midnight on November 17, 1858. Modified Julian dates are based on Julian dates, but adjusted to use midnight rather than noon as a starting point and they use a more recent date as a starting point.
So you have to enter a Julian Date based on either of those starting points.
You can use the reverse functions to get a correct Julian Date: DateTimeToJulianDate/DateTimeToModifiedJulianDate.
In comments it seems as the date you have is the day number of a certain year (sometimes referred to as the Julian Day in meteorological data logging systems).
Then use this:
myDT := EncodeDate(2014,1,1) + yourJulianDay - 1; // If the year is 2014
If your "Julian Date" really is "Julian Day" (ie. the number of days into a given year, a.k.a. Ordinal Date), then you can use the following function to convert it to a TDate (you specify the year the Julian Day should be considered to be in):
uses DateUtils;
FUNCTION JulianDay(Year,Day : Cardinal) : TDate;
BEGIN
Result:=IncDay(EncodeDate(Year,1,1),PRED(Day))
END;
This will return August 14th for JulianDay(2014,226)
I want to store date in my Postgres database.
The only problem is that this date can have optional day or even month.
Example:
User provides time period when he was employed - not necessary full date (day + month + year), but only start year and end year.
However there are users, who worked only from may to october in the same year so month have to be provided too.
How to handle this kind of optional date parts?
Use a proper date type anyway. Do not store text or multiple columns. That would be more expensive and less reliable.
Use the function to_date(), which is fit to deal with your requirements out of the box. For instance, if you call it with a pattern 'YYYYMMDD' and the actual string is missing characters for day, or month and day, it defaults to the first month / day of the year / month:
db=# SELECT to_date('2001', 'YYYYMMDD');
to_date
------------
2001-01-01
db=# SELECT to_date('200103', 'YYYYMMDD');
to_date
------------
2001-03-01
You could store a precision flag indicating year / month / day in addition if you need that.
While the accepted answer is a good one, there is another alternative.
ISO 8601
The ISO 8601 standard defines sensible formats for textual representations of various kinds of date-time values.
A year is represented in the obvious manner, a four-digit number: 2014
A year-month is represented with a required hyphen: 2014-01Note that in other ISO 8601 formats, the hyphen is optional. But not for year month, to avoid ambiguity.
A full date is similar: 2014-08-21 or without optional hyphens: 20140821. I recommend keeping the hyphens.
So you could store the values as text. The length of text would tell you whether it is year-only, year-month, or date.
I've got a date in the following format:
2013-05-04T05:07:09+00:00
I'm using MagicalRecord to map the NSDate automatically. As far as I can see the above date format should comply with MagicalRecord's default date format: yyyy-MM-dd'T'HH:mm:ss'Z'.
I have tried with a custom dateFormat entry in the attribute's user info (see this article):
yyyy-MM-ddTHH:mm:ss+Z, yyyy-MM-dd T HH:mm:ss Z, yyyy-MM-dd'T'HH:mm:ss'+'Z
but none of them work in order to have it parse the date properly and it always returns nil regardless of setting a custom dateFormat or using MagicalRecord's default format.
Let's look at your string:
2013-05-04T05:07:09+00:00
This is:
four digit year
hyphen
zero-padded month
hyphen
zero-padded day of month
'T' character
zero-padded hour
':' character
zero-padded minute
':' character
zero-padded second
timezone (with direction from GMT and a separating colon)
Thus, according to the date format specifiers documentation, the pattern you'd want is:
yyyy-MM-dd'T'HH:mm:ssZZZZZ
Also, be sure to use the en_US_POSIX locale with the NSDateFormatter.
How can I display am or PM with a time display in informix 4GL. In my database the field called crttime_a_p and stores for am "A" and for pm "P". How can I display this in my application as "AM" or "PM". Any help would be appreciated. Thank you.
You'll need to map the database values ('A' ⟶ 'AM', 'P' ⟶ 'PM') and display the mapped value to a FORMONLY field. The field can be used for input if you want. You can add form attributes such as UPSHIFT, AUTONEXT, INCLUDE = ('AM', 'PM') to the field in the form. You just won't be able to use the RECORD LIKE Table.* notation because the field in the DB is CHAR(1) but you need CHAR(2) for display and input.
More seriously, you'll need to consider whether you have to futz with associated time field. If it is a DATETIME field, the time will be in 24 hour notation, and the conversion from 24 hour to AM/PM notation is not entirely straight-forward. Hint: 00:01:02 in 24 hour clock is 12:01:02 AM; 12:02:03 in 24 hour notation is 12:02:03 PM, but 13:03:04 in 24 hour is 1:02:03 PM in AM/PM notation (usually without the leading zero on the hours). See also Converting 24-hour military time to AM/PM time.
If the time field is simply a string, then you probably don't have these problems, but you'll want to design your form carefully to only accept numeric characters (attributes FORMAT and PICTURE?).
Is it possible to format the output of NOW() to a string that displays YYYY-MM-DD?
This is the output of NOW(): 29/02/2012 12.07.37
The reason is, that I need to use the current date in a QUERY.
QUERY only accepts date in the format YYYY-MM-DD . I can't get a date directly from a cell, because it gets formatted as (even if I change the formatting): DD/MM/YYYY
Perhaps some regular expression?
If this is supposed to be an in-cell formula then you can use
=TEXT(NOW(),"yyyy-mm-dd")
I will follow JMax's suggestion and convert my comment to an answer.
Now() returns the current date and time as a number. The integer part gives the date and the fraction part gives the time. If you print or display that date, the default is to give the full date in what Microsoft think's is the local format.
Format(expn, fmt) allows you to convert an expression to a string. For example:
Dim DateStg as String
DateStg = Format(Now(),"yyyy-mm-dd")
fmt defines the format to which the expn is to be converted. fmt is a mixture of code letters (such as: "yyyy", "mm", "dd") and punctuation (such as "-"). "yyyy-mm-dd" appears to meet your current needs but you can also usethe following to format dates:
"mmm" to give three letter month (Jan, Feb, etc.)
"mmmm" to give full name of month (January, February, etc)
"ddd" to give three letter day of week (Mon, Tue, etc)
"dddd" to give full name of day of week (Monday, Tuesday, etc)
In VB.net you can do the following:
Dim dateStr As String = Now().ToString("yyyy-MM-dd")
In C# you can do it like this:
String dateStr = DateTime.Now.ToString("yyyy-MM-dd");