Hi
Can anyone help me how to convert date to number.
If date is 04-15-2019, I want to store it as 20190415 in number format.
I have used =Format ([DateField],"yyyymmdd") and tried to store if as string but even this doesn't seem to work.
Any help is appreciated.
To the best of my knowledge, you cannot Set the Default Value of a Field in a Table to a Formatted Expression involving another Field in the same Table. That being said, and as stated by cactusdata, you can generate this Number within a Query, an example of which would be: - SELECT Table1.ID1, Table1.DateField, Table1.SerialNum, Table1.CustNo,
-
Format$([DateField],"yyyymmdd") & Format([SerialNum],"00") AS DateConv
-
FROM Table1;
-
ID1 DateField SerialNum CustNo DateConv
-
1 12/10/2019 2 12345 2019121002
-
8 7227
You can coerce the Formatted Expression into a LONG, as in: - Dim strTheDate As String
-
Dim lngTheDate As Long
-
-
strTheDate = "4-15-2019"
-
-
lngTheDate = CLng(Format("4-15-2019", "yyyymmdd"))
-
I have tried using =CLng(Format[DateField], "yyyymmdd")) in default value of table properties. However error shows up. The error message Is-The database engine does not recognize either the field 'DateField' in a validation expression, or the default value in table 'Table1'.
Can you give me any advice.
- Format([DateField],"yyyymmdd")
will work, even for Null values, so if "it doesn't work" (whatever that means), something else is going on.
To convert to a number, use Val: - Val(Format([DateField],"yyyymmdd"))
That said, you should always store dates as DateTime and, when retrieved and for display, format for the current purpose.
NeoPa 32,556
Expert Mod 16PB
CactusData is spot-on. If you have the problems as described then they are not connected with your question. It's hard to help with details when you don't share the details. Val() or CLng() should both work fine for what you're describing. What else you're doing wrong is outside of the scope of this discussion - especially as you don't share what else you're doing.
I wish to create a database to enter transactions at my shop.
Each customer is assigned a unique serial number for a transaction. Uptill now I used manual register for entries. Everyday serial number starts from one. To give each transaction a unique identification number I thought of combining date with serial number.
Example a customer assigned serial number 02 today would be given a unique serial number 2019121002. This could be tracked even a year later.
So i wanted to convert date to number and add it to serial number.
However the database engine can't recognise the field. I have attached the table structure and error msg pics.
Thanks.
Don't ever use calculated fields. It's a dead end.
Write a query for this.
To the best of my knowledge, you cannot Set the Default Value of a Field in a Table to a Formatted Expression involving another Field in the same Table. That being said, and as stated by cactusdata, you can generate this Number within a Query, an example of which would be: - SELECT Table1.ID1, Table1.DateField, Table1.SerialNum, Table1.CustNo,
-
Format$([DateField],"yyyymmdd") & Format([SerialNum],"00") AS DateConv
-
FROM Table1;
-
ID1 DateField SerialNum CustNo DateConv
-
1 12/10/2019 2 12345 2019121002
-
OR..... Instead of insisting that the field is a numerical value, you could have it as short text of 13 characters. Then your serial number number could be: "2019-12-10-02".
Conversion back to dates is simple: - dtOrderDate = cDate(Left([SerialNumber], 10))
It just depends upon what info you need to track in this Serial Number.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: sumeet |
last post by:
how do i convert a yyyymmdd format to yyyy,mm,dd format. also i want to know how do i get the number of days between two dates which r in the format yyyymmdd.
how to convert date into unix time...
|
by: galsaba |
last post by:
What would be the function to convert date to the number of date
for example, 2/14/05 is 45, becuse this is the 45th day of the year.
What would be the function?
Where can I find info on the web...
|
by: whatluo |
last post by:
Hi, all
I'm now working on a program which will convert dec number to
hex and oct and bin respectively, I've checked the clc but with no
luck, so can anybody give me a hit how to make this done...
|
by: sparkle |
last post by:
Hi,
Does anybody know how to convert date to ticks from a dateTimePicker?
What I'm using now isn't working.
I'm trying to use a dateTimePicker to set an appointment in Outlook
with a...
|
by: Totto |
last post by:
Hi,
Is it possible to convert date to
dd mon yyyy hh:mi(24h)
Thanks Totto
|
by: VK |
last post by:
http://groups.google.com/group/comp.lang.javascript/browse_frm/thread/
b495b4898808fde0>
is more than one month old - this may pose problem for posting over
some news servers. This is why I'm...
|
by: Lyosha |
last post by:
Converting binary to base 10 is easy:
255
Converting base 10 number to hex or octal is easy:
'0144'
'0x64'
Is there an *easy* way to convert a number to binary?
|
by: KalariaNitya |
last post by:
Hello All,
I want to convert Date to Hindu Calender. For e.g. today is 12th sep'2008 so convert it to bhadarvo sud baras.
can anybody help me how to do that?
thanking u in advanced..
|
by: subedimite |
last post by:
Here I am with another question being a very new VBA user.
I have this scenario to work with: I would think this is fairly common routine of work for VBA.
I have a string of hex contents as...
|
by: Irfan iffi |
last post by:
how to convert date of bith in (dd-mon-yyyy) this formate ? plz kindly help me
How to convert date of birth in in years in oracle form 6i
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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,...
|
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...
| |