| |

VerySource

 Forgot password?
 Register
Search
View: 1067|Reply: 5

HELP

[Copy link]

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 China

Post time: 2020-3-10 16:00:02
| Show all posts |Read mode
String si, SubStr, name;
   si = DateToStr (Date ());
   SubStr = si.SubString (5, StrToInt (si.Length ()-2)); / * Remove the month and day of the birth date * /
   data-> personquery-> Close ();
   data-> personquery-> SQL-> Clear ();
   data-> personquery-> SQL-> Add ("select * from perinf where birthday like '%" + SubStr + "%'");
   data-> personquery-> Open ();
   if (data-> personquery-> RecordCount! = 0)
{while (! data-> personquery-> Eof)
    {
     name = data-> personquery-> FieldValues ​​["name"];
     data-> personquery-> Next ();
     }
   ShowMessage ("Today is'" + name + "'' s birthday, go and send my best wishes!");
} Query results are not possible, there may be a problem with the SQL statement. Please advise, how to write
Reply

Use magic Report

0

Threads

15

Posts

11.00

Credits

Newbie

Rank: 1

Credits
11.00

 China

Post time: 2020-6-6 05:30:01
| Show all posts
It may be that the number you get when you take out the birth month and day is "-1-5" in 2017-1-5.
Change it like this:
si=Date().FormatString("yyyymmdd");
The data taken out in this way is that the birth month and day are "0105".
StrToInt(si.Length()-2);'//StrToInt is not needed here, si.Length() is of type int.
Reply

Use magic Report

0

Threads

11

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-6-8 01:00:01
| Show all posts
It is really difficult to grasp the date and time!
It's better to know what format the date and time are in your database first, and then use FormatDateTime() to format the date of the day you get to obtain the month and day information.
As for the SQL statement, if your birthday field is in a short date format, it might be better to write LIKE'____-"+strMonth+"-"+strDay+"'
Reply

Use magic Report

1

Threads

4

Posts

5.00

Credits

Newbie

Rank: 1

Credits
5.00

 Unknown

 Author| Post time: 2020-6-10 21:00:01
| Show all posts
Thank you very much for your attention, but I hope to write more details. I have tried both methods and the record is still 0. For example, if the first one is 0105, how to write sql statement. The format in my library is 2016-1-5. Thank you. Very anxious
Reply

Use magic Report

0

Threads

11

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-7-5 20:45:01
| Show all posts
Sorry, the following is the positive solution: (applicable to SQL Server, Access and other MS databases)
AnsiString SssMonth=FormatDateTime("M",Date()); //Get today's month
AnsiString SssDay=FormatDateTime("d",Date()); //Get today's day

AnsiString SQLStr="SELECT * FROM perinf WHERE (MONTH(birthday) = "+SssMonth+") AND (DAY(birthday) = "+SssDay+")";

...

data->personquery->SQL->Add(SQLStr);

...

You have already written the omitted parts
Reply

Use magic Report

0

Threads

11

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-7-5 21:15:01
| Show all posts
The birthday field in your database must be DateTime
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list