473,772 Members | 2,402 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parse the date into integer

28 New Member
I' making an database application. In one form (Input data Form), I need to fill the text field with the reference number automatically. This number must be start with date of today. For the example, 2007092401. And the text field must be filled with the largest number in database (the largest of that day).
Firstly, the form will check if there's a number start with today's date. If it's not NULL, the form takes the biggest one. But if it returns NULL, I wanna make a number that start with today's date. But I don't know how to join the date (I take the date with time's function) and the '01'...
(PS : the type of my reference number's field in MySQL is integer)

Here's a piece of my code.

Expand|Select|Wrap|Line Numbers
  1. $now=time();
  2. $ref=date("Ymd",$now);
  3.  
  4. $refku=implode($ref,"01");  // I need some help here
  5.  
  6. $peri="select max(noreff) as A from tblref where noreff like '$ref%' ";
  7. $hasil=mysql_query($peri);
  8. $row=mysql_fetch_array($hasil);
  9.  
  10. if($row!=NULL)
  11. {
  12. echo (" <input name=\"noreff\" type=\"text\" value=\"$row[A]\" maxlength=10></td> ");
  13. }
  14.  
  15. else
  16. {
  17. echo (" <input name=\"noreff\" type=\"text\" value=\"$refku\" maxlength=10 /></td> ");
  18. }    
  19.  
---Thank You---
Sep 24 '07 #1
6 10096
Atli
5,058 Recognized Expert Expert
Hi momogi.

You could simply do this:
Expand|Select|Wrap|Line Numbers
  1. $refku= $ref ."01";
  2.  
$refku would technically be a string, but PHP is smart enough to convert it into whatever type it needs to be in various situations.

For example:
Expand|Select|Wrap|Line Numbers
  1. $refku = date("Ymd", time()) . "01";
  2. # Now $refku is a string "2007092401"
  3.  
  4. echo "refku plus one: ". ($refku + 1);
  5. # Will output "refku plus one: 2007092402"
  6.  
Sep 24 '07 #2
momogi
28 New Member
Hi momogi.

You could simply do this:
Expand|Select|Wrap|Line Numbers
  1. $refku= $ref ."01";
  2.  
$refku would technically be a string, but PHP is smart enough to convert it into whatever type it needs to be in various situations.

For example:
Expand|Select|Wrap|Line Numbers
  1. $refku = date("Ymd", time()) . "01";
  2. # Now $refku is a string "2007092401"
  3.  
  4. echo "refku plus one: ". ($refku + 1);
  5. # Will output "refku plus one: 2007092402"
  6.  
Hi Atli...

thx 4 your reply... :)

But I have to say that it doesn't work.
My text field still empty,,, (except I enter the today's reference manually in database).

Is there another solution? thx b4.
Sep 24 '07 #3
code green
1,726 Recognized Expert Top Contributor
But I have to say that it doesn't work.Is there another solution?
Atli's solution will work.
You have obviously asked the wrong question which was
Parse the date into integer
My text field still empty,,,
Is this you problem? If so, what text field and where?
Sep 24 '07 #4
momogi
28 New Member
Atli's solution will work.
You have obviously asked the wrong question which was Is this you problem? If so, what text field and where?
Hi...

The text field is a field where I wanna put my reference number automatically. its placed in the top of my form.
if the user haven't fill the form at the day, the form will generate the reference number automatically which started with the date.

hope that was clear 4 you. I'm sorry if I was ask the wrong question...

gbu.
Sep 25 '07 #5
Atli
5,058 Recognized Expert Expert
Try something like this:
Expand|Select|Wrap|Line Numbers
  1. # Execute query and get row
  2. $ref = date("Ymd", time());
  3. $query = "SELECT MAX(noreff) AS 'A' FROM tblref WHERE noreff LIKE '$ref%' ";
  4. $result=mysql_query($query) or die("Query failed");
  5. $row=mysql_fetch_assoc($result);
  6.  
  7. # Create reference
  8. if(@isset($row['A'])) {
  9.   $refku = $row['A'];
  10. }
  11. else {
  12.   $refku = $ref . "01";
  13. }
  14.  
  15. # Print reference
  16. echo "<input name=\"noreff\" type=\"text\" value=\"$refku\" maxlength=10 /></td> "
  17.  
Sep 25 '07 #6
momogi
28 New Member
Try something like this:
Expand|Select|Wrap|Line Numbers
  1. # Execute query and get row
  2. $ref = date("Ymd", time());
  3. $query = "SELECT MAX(noreff) AS 'A' FROM tblref WHERE noreff LIKE '$ref%' ";
  4. $result=mysql_query($query) or die("Query failed");
  5. $row=mysql_fetch_assoc($result);
  6.  
  7. # Create reference
  8. if(@isset($row['A'])) {
  9.   $refku = $row['A'];
  10. }
  11. else {
  12.   $refku = $ref . "01";
  13. }
  14.  
  15. # Print reference
  16. echo ("<input name=\"noreff\" type=\"text\" value=\"$refku\" maxlength=10 /></td> "
  17. }    
  18.  
whoaaa... it works!!!

thanks...

thanks... :)

and thanks... :D
Sep 25 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

7
1737
by: serpent17 | last post by:
Hello all, I have this line of numbers: 04242005 18:20:42-0.000002, 271.1748608, , , repeated several times in a text file and I would like each element to be part of a vector. how do I do this ? I am not very capable in using
4
43537
by: Matteo | last post by:
Hy everybody. I'm not a html writer, but a sysadmin who's trying to help a user able to compile an online form with IE but not with Mozilla (Moz1.6, Ns7.1, Firefox 0.8+) due to a javascript date check. Let's go straight to the point: <script language="JavaScript"> alert("Date: "+Date.parse("2000-01-01"))
3
4747
by: Ken Bush | last post by:
How can I write an update query that removes part of a field? Like if I have a field with values such as 8/3/68 (a birthday obviously) and I need to put values in a new column but I need everything after and including the final / removed to end up with simply 8/3
1
1984
by: u473 | last post by:
I am still a beginner with VBA and I need the VBA Code for the following problem. I have a list of activities with their Scheduled Start date, Duration, and Working hours in Table1. I need to loop thru each record in Table1, split the long activity durations according to their Working Hours shown in the Calendar field and write these records to Table2.
5
2250
by: Doug Bell | last post by:
Hi, I have some data in the format of yyyymmdd (Int32) that I want to display, in a datagrid, formatted in International Date Format dd MM yyyy. Any suggestions on an efficient approach? Thanks, Doug
2
2818
by: Bob Altman | last post by:
Hi all, I need to simulate current date and time and provide integer values for the current year, month, day, hour, minute, second, and millisec. I need to do this in unmanaged C++. My first inclination is to do roughly the same thing that I would do in managed code: I would maintain a 64-bit integer value that represents the number of millisec. (or nanosec.) since some date. I would periodically increment this integer by the...
29
2909
by: gs | last post by:
let say I have to deal with various date format and I am give format string from one of the following dd/mm/yyyy mm/dd/yyyy dd/mmm/yyyy mmm/dd/yyyy dd/mm/yy mm/dd/yy dd/mmm/yy mmm/dd/yy
3
4290
by: Ben | last post by:
Hi, Can anyone explain why this, Date.parse("Jan 1, 1970") equals this, 18000000 ? Microsoft's documentation reports this, " The parse method returns an integer value representing the number of
2
2119
by: dpw.asdf | last post by:
I have been searching all over for a solution to this. I am new to Python, so I'm a little lost. Any pointers would be a great help. I have a couple hundred emails that contain data I would like to incorporate into a database or CSV file. I want to search the email for specific text. The emails basically look like this:
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10103
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9911
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8934
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7460
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6713
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.