CariDotMy

 Forgot password?
 Register

ADVERTISEMENT

View: 4300|Reply: 9

How to convert varchar to datetime in php? database type is MSSQL?

[Copy link]
Post time 4-9-2012 11:05 AM | Show all posts |Read mode
Salam,

nak tanya,
mcm mana sy nak convert data dari format varchar ke date dlm php. Database yg sy gunakan adalah ms sql. yg sy google kebanyyakkannya pakai mysql.

cth, ktlah field tarikh varchar , field name = TARIKHSTR, so sy nak convert ker field date, field name = TARIKH,
mcm mana rupe coding n sintak dia dlm php ?format date tuh dd/mm/yyyy

anyone can help?

Last edited by isms on 4-9-2012 11:20 AM

Reply

Use magic Report


ADVERTISEMENT


Post time 4-9-2012 01:06 PM | Show all posts
Kenapa field pada table tak pakai type datetime?
Reply

Use magic Report

 Author| Post time 4-9-2012 02:46 PM | Show all posts
chuki2 posted on 4-9-2012 01:06 PM
Kenapa field pada table tak pakai type datetime?

saya pun x tahu sbb apa bos sy pakai varchar sebelum ne

Reply

Use magic Report

Post time 4-9-2012 02:52 PM | Show all posts
kalau ms sql ... format date.. store by default = ("MM/dd/yyyy")..
bukan "dd/mm/yyyy"
contoh dlm .net..

dim YourDate as new date
YourDate = CDate(date.now.tostring)
insert into [table1] (columndate) VALUES (YourDate.tostring("MM/dd/yyyy"))

dlm php xtahu...
Reply

Use magic Report

Post time 5-9-2012 11:42 AM | Show all posts
Kalau dalam C# saya buat macam ini sahaja..
  1. DateTime enteredDate = DateTime.Parse(enteredString);
Copy the Code
Reply

Use magic Report

Post time 6-9-2012 08:45 AM | Show all posts
Kompius aku dgn soklan ko nih..

Kalau ikut pemahaman aku, ko nak copy value dari field TARIKHSTR (varchar) ke field TARIKH (datetime).. betul mcm tu?? Kalau nak buat camtu, tak perlu pun PHP.. CUma run query je kat MSSQL tu

katakanlah ko punya database bernama AYAM dan nama table adalah ITIK
  1. set dateformat dmy
  2. use AYAM
  3. update ITIK
  4. set TARIKH = CAST(TARIKHSTR AS DATETIME)
Copy the Code
p/s: kod tu aku tak test pun.. cuba la dulu
Reply

Use magic Report

Follow Us
 Author| Post time 6-9-2012 09:07 AM | Show all posts
nalis posted on 6-9-2012 08:45 AM
Kompius aku dgn soklan ko nih..

Kalau ikut pemahaman aku, ko nak copy value dari field TARIKHSTR  ...

heehee sorry, mebi ayat tunggang langgang
tp citernya lebih kurang gtu ler..

sbb database simpan date dlm varchar,
bila sy nak guna sql statement 'BETWEEN' antara 2 tarikh, cth : dari 1/1/2012 hingga 1/12/2012, field tarikh kena dalam btk datetime, sbb tuh ler sy nak convert field varchar ke datetime.

sy punya coding pakai php, sbb tuh ler tanya mcm2 tuh, ingat nak bg org paham, pakai programming langguange per, database per...heheh sorry,
anyway thanks, akan dicuba

Reply

Use magic Report

 Author| Post time 6-9-2012 09:10 AM | Show all posts
nalis posted on 6-9-2012 08:45 AM
Kompius aku dgn soklan ko nih..

Kalau ikut pemahaman aku, ko nak copy value dari field TARIKHSTR  ...

pesal yg ko ckp run guery kt mssql tuh kan...
aku x nak ubah apa2 kt database, meaning biarlah filed tarikh tuh menten as varchar

cuma aku nak convert ms wat coding kt php
sbb tuh aku nak convert kt php coding


coding ne, kalau aku run kt mssql, akan ubah aku nyer dbase kan?

Reply

Use magic Report


ADVERTISEMENT


Post time 6-9-2012 09:14 AM | Show all posts
isms posted on 6-9-2012 09:10 AM
pesal yg ko ckp run guery kt mssql tuh kan...
aku x nak ubah apa2 kt database, meaning biarlah fi ...

rasanya ko ni merujuk kepada permasalah ko yg aritu kan? cuba rujuk jawapan aku ritu http://mforum.cari.com.my/forum. ... amp;fromuid=1085642
Reply

Use magic Report

 Author| Post time 6-9-2012 09:44 AM | Show all posts
nalis posted on 6-9-2012 09:14 AM
rasanya ko ni merujuk kepada permasalah ko yg aritu kan? cuba rujuk jawapan aku ritu http://mforum ...

oh ok, thanks, x perasan ada reply kt thread tuh

Reply

Use magic Report

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

Points Rules

 

ADVERTISEMENT



 

ADVERTISEMENT


 


ADVERTISEMENT
Follow Us

ADVERTISEMENT


Mobile|Archiver|Mobile*default|About Us|CariDotMy

31-12-2024 06:03 AM GMT+8 , Processed in 0.118113 second(s), 24 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

Quick Reply To Top Return to the list