473,396 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Parse the date into integer

28
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 10078
Atli
5,058 Expert 4TB
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
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 Expert 1GB
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
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 Expert 4TB
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
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
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...
4
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...
3
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...
1
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...
5
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? ...
2
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...
29
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
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...
2
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
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,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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,...

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.