The date field is transferred to the week. Could you help me? Delphi/Windows SDK/API
Http://www.delphi2007.net/DelphiDB/html/delphi_20061220145356199.html
In the database, only the date field does not have a week, and the customer requires that the day of the week be displayed. select datename (weekday, date) from table can be implemented in SQL, but datenane is not defined in Delphi. Is there any way to generate a date field for the date field?
Sinking too fast ~~~ Come on, help me ~
Case dayofweek (date)
1: Result: = 'sunday ';
2: Result: = 'monday ';
3: Result: = 'tuesday ';
4: Result: = 'weday ';
5: Result: = 'thurs ';
6: Result: = 'Friday ';
7: Result: = 'saturday ';
End;
To: ron_xin (xingyu)
I know that I mean to convert an existing date into a week during data inventory query. Is it clear enough?
With adoquery1 do
Begin
Close;
SQL. Clear;
SQL. Text: = 'select datename (weekday, date) Week from table ';
Open;
Showmessage (fieldbyname ('Week '). asstring );
End;
To: 47522341 (sleeping till)
I used this method at the beginning, but when executing Delphi, the system prompts that datename is undefined. Can you run it? What did you do?
I am using an Access database.
Dayofweek (date)
It should be an alias problem ~ '
Select datename (weekday, date) as datenane from table
I am using an Access database! Will datename be not supported ?? Because I can use another SQL database table to execute
Create a query in access and call this query in Delphi
Functions used for access are used in queries.
To: skertone ()
Can I give an example?
Access is not supported '~ Not all SQL functions can be used in access '~
Three methods
1. Based on datepart ('w', date), extract the day of the day as the day of the week, and then convert it through IIF, that is, Layer 7.
Select date, IIF (datepart ('w', date) = 1, 'sunday', IIF (datepart ('w', date) = 2, 'monday ', 'Continue writing Based on IIF ') from table
2. Retrieve the day of the week based on datepart ('w', date), and create a search field in Delphi. Of course, you must create another table to save the number corresponding to the day of the week.
3. Delphi format Fields
Yes, it is because datename does not support access. Is there any good way to display the week during query?
To: Thank you (Xingxing farm)
Can I Format an entire field? Can I explain it?
Thank you. What does your IIF mean? Delphi always prompts syntax errors.
I really admire you
The first solution is pure SQL, which must be executed in tadoquery. I don't know how you use it in Delphi.
The third method is to set through the displayvalue attribute.
Haha, it's troublesome for new users. Sorry.
I executed it in daoquery, but it seems that I cannot recognize IIF.
Finally, you can compile it. Check whether the data is correct.
Thank you. The first method you used was to generate seven columns ??
● Function dayofweek (date: tdatetime): integer;
Description
Dayofweek returns the day of the week of the specified date
An integer
1 and 7, where Sunday is the first day of the week and
Saturday is the seventh.
Note: dayofweek is not compliant with the ISO 8601 standard,
Which defines Monday
As the first day of the week. For an ISO 8601 compliant
Version, use the dayoftheweek
Function instead.
Description:
According to the given tdatetime type parameter date, the dayofweek function obtains the day of the week, from 1 to 7.
Sunday is the first day of the week, while Saturday is the seventh day.
Extract the date first, and then convert it in Delphi